mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-22 08:47:10 +08:00
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 { Button } from '@affine/component/ui/button';
|
||||
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 type { Workspace } from '@affine/core/modules/workspace';
|
||||
import { useI18n } from '@affine/i18n';
|
||||
import { universalId } from '@affine/nbstore';
|
||||
import track from '@affine/track';
|
||||
import { ExportIcon } from '@blocksuite/icons/rc';
|
||||
import { useService } from '@toeverything/infra';
|
||||
import { useState } from 'react';
|
||||
|
||||
@@ -18,14 +18,11 @@ interface ExportPanelProps {
|
||||
export const DesktopExportPanel = ({ workspace }: ExportPanelProps) => {
|
||||
const t = useI18n();
|
||||
const [saving, setSaving] = useState(false);
|
||||
const isOnline = useSystemOnline();
|
||||
const desktopApi = useService(DesktopApiService);
|
||||
const isLocalWorkspace = workspace.flavour === 'local';
|
||||
|
||||
const [fullSyncing, setFullSyncing] = useState(false);
|
||||
const [fullSynced, setFullSynced] = useState(false);
|
||||
|
||||
const shouldWaitForFullSync = !isLocalWorkspace && isOnline && !fullSynced;
|
||||
const [fullSynced, setFullSynced] = useState(isLocalWorkspace);
|
||||
|
||||
const fullSync = useAsyncCallback(async () => {
|
||||
setFullSyncing(true);
|
||||
@@ -65,36 +62,55 @@ export const DesktopExportPanel = ({ workspace }: ExportPanelProps) => {
|
||||
}
|
||||
}, [desktopApi, saving, t, workspace]);
|
||||
|
||||
if (shouldWaitForFullSync) {
|
||||
if (fullSynced) {
|
||||
return (
|
||||
<SettingRow name={t['Export']()} desc={t['Full Sync Description']()}>
|
||||
<SettingRow
|
||||
name={t['Full Backup']()}
|
||||
desc={t['Full Backup Description']()}
|
||||
>
|
||||
<Button
|
||||
data-testid="export-affine-full-sync"
|
||||
onClick={fullSync}
|
||||
loading={fullSyncing}
|
||||
variant="primary"
|
||||
data-testid="export-affine-backup"
|
||||
onClick={onExport}
|
||||
disabled={saving}
|
||||
>
|
||||
{t['Full Sync']()}
|
||||
{t['Full Backup']()}
|
||||
</Button>
|
||||
</SettingRow>
|
||||
);
|
||||
}
|
||||
|
||||
const button =
|
||||
isLocalWorkspace || isOnline ? t['Export']() : t['Export(Offline)']();
|
||||
const desc =
|
||||
isLocalWorkspace || isOnline
|
||||
? t['Export Description']()
|
||||
: t['Export Description(Offline)']();
|
||||
|
||||
return (
|
||||
<SettingRow name={t['Export']()} desc={desc}>
|
||||
<Button
|
||||
data-testid="export-affine-backup"
|
||||
onClick={onExport}
|
||||
disabled={saving}
|
||||
<>
|
||||
<SettingRow
|
||||
name={t['Full Backup']()}
|
||||
desc={
|
||||
fullSynced ? t['Full Backup Description']() : t['Full Backup Hint']()
|
||||
}
|
||||
>
|
||||
{button}
|
||||
</Button>
|
||||
</SettingRow>
|
||||
<Button
|
||||
variant="primary"
|
||||
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;
|
||||
/**
|
||||
* `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;
|
||||
/**
|
||||
* `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;
|
||||
["Quick Export Description"](): string;
|
||||
/**
|
||||
* `Export failed`
|
||||
*/
|
||||
|
||||
@@ -38,12 +38,11 @@
|
||||
"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 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",
|
||||
"Export(Offline)": "Export (Offline)",
|
||||
"Full Sync": "Full Sync",
|
||||
"Export Description": "You can export the entire Workspace data for backup, and the exported data can be re-imported.",
|
||||
"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.",
|
||||
"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.",
|
||||
"Full Backup": "Full Backup",
|
||||
"Full Backup Description": "Export a complete workspace backup",
|
||||
"Full Backup Hint": "Sync all cloud data and export a complete workspace backup",
|
||||
"Quick Export": "Quick Export",
|
||||
"Quick Export Description": "Skip cloud synchronization and quickly export current data(some attachments or docs may be missing)",
|
||||
"Export failed": "Export failed",
|
||||
"Export success": "Export success",
|
||||
"Export to HTML": "Export to HTML",
|
||||
|
||||
Reference in New Issue
Block a user