chore(core): allow quick export (#11295)
This commit is contained in:
@@ -2,12 +2,12 @@ import { notify } from '@affine/component';
|
|||||||
import { SettingRow } from '@affine/component/setting-components';
|
import { SettingRow } from '@affine/component/setting-components';
|
||||||
import { Button } from '@affine/component/ui/button';
|
import { Button } from '@affine/component/ui/button';
|
||||||
import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hooks';
|
import { useAsyncCallback } from '@affine/core/components/hooks/affine-async-hooks';
|
||||||
import { useSystemOnline } from '@affine/core/components/hooks/use-system-online';
|
|
||||||
import { DesktopApiService } from '@affine/core/modules/desktop-api';
|
import { DesktopApiService } from '@affine/core/modules/desktop-api';
|
||||||
import type { Workspace } from '@affine/core/modules/workspace';
|
import type { Workspace } from '@affine/core/modules/workspace';
|
||||||
import { useI18n } from '@affine/i18n';
|
import { useI18n } from '@affine/i18n';
|
||||||
import { universalId } from '@affine/nbstore';
|
import { universalId } from '@affine/nbstore';
|
||||||
import track from '@affine/track';
|
import track from '@affine/track';
|
||||||
|
import { ExportIcon } from '@blocksuite/icons/rc';
|
||||||
import { useService } from '@toeverything/infra';
|
import { useService } from '@toeverything/infra';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
@@ -18,14 +18,11 @@ interface ExportPanelProps {
|
|||||||
export const DesktopExportPanel = ({ workspace }: ExportPanelProps) => {
|
export const DesktopExportPanel = ({ workspace }: ExportPanelProps) => {
|
||||||
const t = useI18n();
|
const t = useI18n();
|
||||||
const [saving, setSaving] = useState(false);
|
const [saving, setSaving] = useState(false);
|
||||||
const isOnline = useSystemOnline();
|
|
||||||
const desktopApi = useService(DesktopApiService);
|
const desktopApi = useService(DesktopApiService);
|
||||||
const isLocalWorkspace = workspace.flavour === 'local';
|
const isLocalWorkspace = workspace.flavour === 'local';
|
||||||
|
|
||||||
const [fullSyncing, setFullSyncing] = useState(false);
|
const [fullSyncing, setFullSyncing] = useState(false);
|
||||||
const [fullSynced, setFullSynced] = useState(false);
|
const [fullSynced, setFullSynced] = useState(isLocalWorkspace);
|
||||||
|
|
||||||
const shouldWaitForFullSync = !isLocalWorkspace && isOnline && !fullSynced;
|
|
||||||
|
|
||||||
const fullSync = useAsyncCallback(async () => {
|
const fullSync = useAsyncCallback(async () => {
|
||||||
setFullSyncing(true);
|
setFullSyncing(true);
|
||||||
@@ -65,36 +62,55 @@ export const DesktopExportPanel = ({ workspace }: ExportPanelProps) => {
|
|||||||
}
|
}
|
||||||
}, [desktopApi, saving, t, workspace]);
|
}, [desktopApi, saving, t, workspace]);
|
||||||
|
|
||||||
if (shouldWaitForFullSync) {
|
if (fullSynced) {
|
||||||
return (
|
return (
|
||||||
<SettingRow name={t['Export']()} desc={t['Full Sync Description']()}>
|
<SettingRow
|
||||||
|
name={t['Full Backup']()}
|
||||||
|
desc={t['Full Backup Description']()}
|
||||||
|
>
|
||||||
<Button
|
<Button
|
||||||
data-testid="export-affine-full-sync"
|
variant="primary"
|
||||||
onClick={fullSync}
|
data-testid="export-affine-backup"
|
||||||
loading={fullSyncing}
|
onClick={onExport}
|
||||||
|
disabled={saving}
|
||||||
>
|
>
|
||||||
{t['Full Sync']()}
|
{t['Full Backup']()}
|
||||||
</Button>
|
</Button>
|
||||||
</SettingRow>
|
</SettingRow>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const button =
|
|
||||||
isLocalWorkspace || isOnline ? t['Export']() : t['Export(Offline)']();
|
|
||||||
const desc =
|
|
||||||
isLocalWorkspace || isOnline
|
|
||||||
? t['Export Description']()
|
|
||||||
: t['Export Description(Offline)']();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<SettingRow name={t['Export']()} desc={desc}>
|
<>
|
||||||
<Button
|
<SettingRow
|
||||||
data-testid="export-affine-backup"
|
name={t['Full Backup']()}
|
||||||
onClick={onExport}
|
desc={
|
||||||
disabled={saving}
|
fullSynced ? t['Full Backup Description']() : t['Full Backup Hint']()
|
||||||
|
}
|
||||||
>
|
>
|
||||||
{button}
|
<Button
|
||||||
</Button>
|
variant="primary"
|
||||||
</SettingRow>
|
data-testid="export-affine-full-sync"
|
||||||
|
onClick={fullSync}
|
||||||
|
loading={fullSyncing}
|
||||||
|
disabled={fullSyncing}
|
||||||
|
prefix={<ExportIcon />}
|
||||||
|
>
|
||||||
|
{t['Full Backup']()}
|
||||||
|
</Button>
|
||||||
|
</SettingRow>
|
||||||
|
<SettingRow
|
||||||
|
name={t['Quick Export']()}
|
||||||
|
desc={t['Quick Export Description']()}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
data-testid="export-affine-backup"
|
||||||
|
onClick={onExport}
|
||||||
|
disabled={saving}
|
||||||
|
>
|
||||||
|
{t['Quick Export']()}
|
||||||
|
</Button>
|
||||||
|
</SettingRow>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -192,29 +192,25 @@ export function useAFFiNEI18N(): {
|
|||||||
*/
|
*/
|
||||||
["Enable cloud hint"](): string;
|
["Enable cloud hint"](): string;
|
||||||
/**
|
/**
|
||||||
* `Export`
|
* `Full Backup`
|
||||||
*/
|
*/
|
||||||
Export(): string;
|
["Full Backup"](): string;
|
||||||
/**
|
/**
|
||||||
* `Export (Offline)`
|
* `Export a complete workspace backup`
|
||||||
*/
|
*/
|
||||||
["Export(Offline)"](): string;
|
["Full Backup Description"](): string;
|
||||||
/**
|
/**
|
||||||
* `Full Sync`
|
* `Sync all cloud data and export a complete workspace backup`
|
||||||
*/
|
*/
|
||||||
["Full Sync"](): string;
|
["Full Backup Hint"](): string;
|
||||||
/**
|
/**
|
||||||
* `You can export the entire Workspace data for backup, and the exported data can be re-imported.`
|
* `Quick Export`
|
||||||
*/
|
*/
|
||||||
["Export Description"](): string;
|
["Quick Export"](): string;
|
||||||
/**
|
/**
|
||||||
* `You can export the entire Workspace data for backup, and the exported data can be re-imported. But you are offline now which will cause the exported data not up to date.`
|
* `Skip cloud synchronization and quickly export current data(some attachments or docs may be missing)`
|
||||||
*/
|
*/
|
||||||
["Export Description(Offline)"](): string;
|
["Quick Export Description"](): string;
|
||||||
/**
|
|
||||||
* `You can export the entire Workspace data for backup, and the exported data can be re-imported. But you must sync all cloud data first to keep your exported data up to date.`
|
|
||||||
*/
|
|
||||||
["Full Sync Description"](): string;
|
|
||||||
/**
|
/**
|
||||||
* `Export failed`
|
* `Export failed`
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -38,12 +38,11 @@
|
|||||||
"Enable AFFiNE Cloud": "Enable AFFiNE Cloud",
|
"Enable AFFiNE Cloud": "Enable AFFiNE Cloud",
|
||||||
"Enable AFFiNE Cloud Description": "If enabled, the data in this workspace will be backed up and synchronised via AFFiNE Cloud.",
|
"Enable AFFiNE Cloud Description": "If enabled, the data in this workspace will be backed up and synchronised via AFFiNE Cloud.",
|
||||||
"Enable cloud hint": "The following functions rely on AFFiNE Cloud. All data is stored on the current device. You can enable AFFiNE Cloud for this workspace to keep data in sync with the cloud.",
|
"Enable cloud hint": "The following functions rely on AFFiNE Cloud. All data is stored on the current device. You can enable AFFiNE Cloud for this workspace to keep data in sync with the cloud.",
|
||||||
"Export": "Export",
|
"Full Backup": "Full Backup",
|
||||||
"Export(Offline)": "Export (Offline)",
|
"Full Backup Description": "Export a complete workspace backup",
|
||||||
"Full Sync": "Full Sync",
|
"Full Backup Hint": "Sync all cloud data and export a complete workspace backup",
|
||||||
"Export Description": "You can export the entire Workspace data for backup, and the exported data can be re-imported.",
|
"Quick Export": "Quick Export",
|
||||||
"Export Description(Offline)": "You can export the entire Workspace data for backup, and the exported data can be re-imported. But you are offline now which will cause the exported data not up to date.",
|
"Quick Export Description": "Skip cloud synchronization and quickly export current data(some attachments or docs may be missing)",
|
||||||
"Full Sync Description": "You can export the entire Workspace data for backup, and the exported data can be re-imported. But you must sync all cloud data first to keep your exported data up to date.",
|
|
||||||
"Export failed": "Export failed",
|
"Export failed": "Export failed",
|
||||||
"Export success": "Export success",
|
"Export success": "Export success",
|
||||||
"Export to HTML": "Export to HTML",
|
"Export to HTML": "Export to HTML",
|
||||||
|
|||||||
Reference in New Issue
Block a user