forked from toeverything/AFFiNE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): add workspace quota panel for team workspace (toeverythin…
…g#9085) close AF-1917 AF-1685 AF-1730
- Loading branch information
Showing
8 changed files
with
224 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...esktop/dialogs/setting/workspace-setting/new-workspace-setting-detail/workspace-quota.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { ErrorMessage, Skeleton } from '@affine/component'; | ||
import { SettingRow } from '@affine/component/setting-components'; | ||
import { WorkspacePermissionService } from '@affine/core/modules/permissions'; | ||
import { WorkspaceQuotaService } from '@affine/core/modules/quota'; | ||
import { useI18n } from '@affine/i18n'; | ||
import { useLiveData, useService } from '@toeverything/infra'; | ||
import { cssVarV2 } from '@toeverything/theme/v2'; | ||
import { useEffect } from 'react'; | ||
|
||
import * as styles from './style.css'; | ||
|
||
export const WorkspaceQuotaPanel = () => { | ||
const t = useI18n(); | ||
return ( | ||
<SettingRow | ||
name={t['com.affine.workspace.storage']()} | ||
desc="" | ||
spreadCol={false} | ||
> | ||
<StorageProgress /> | ||
</SettingRow> | ||
); | ||
}; | ||
|
||
export const StorageProgress = () => { | ||
const t = useI18n(); | ||
const workspacePermissionService = useService( | ||
WorkspacePermissionService | ||
).permission; | ||
const workspaceQuotaService = useService(WorkspaceQuotaService).quota; | ||
const isTeam = useLiveData(workspacePermissionService.isTeam$); | ||
const isLoading = useLiveData(workspaceQuotaService.isLoading$); | ||
const usedFormatted = useLiveData(workspaceQuotaService.usedFormatted$); | ||
const maxFormatted = useLiveData(workspaceQuotaService.maxFormatted$); | ||
const percent = useLiveData(workspaceQuotaService.percent$); | ||
const color = useLiveData(workspaceQuotaService.color$); | ||
|
||
useEffect(() => { | ||
// revalidate quota to get the latest status | ||
workspaceQuotaService.revalidate(); | ||
}, [workspaceQuotaService]); | ||
|
||
const loadError = useLiveData(workspaceQuotaService.error$); | ||
|
||
if (isLoading) { | ||
if (loadError) { | ||
return <ErrorMessage>Load error</ErrorMessage>; | ||
} | ||
return <Skeleton height={42} />; | ||
} | ||
|
||
if (!isTeam) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className={styles.storageProgressContainer}> | ||
<div className={styles.storageProgressWrapper}> | ||
<div className="storage-progress-desc"> | ||
<span>{t['com.affine.storage.used.hint']()}</span> | ||
<span> | ||
{usedFormatted}/{maxFormatted} | ||
</span> | ||
</div> | ||
<div className="storage-progress-bar-wrapper"> | ||
<div | ||
className={styles.storageProgressBar} | ||
style={{ | ||
width: `${percent}%`, | ||
backgroundColor: color ?? cssVarV2('toast/iconState/regular'), | ||
}} | ||
></div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters