1.adjust export/import database;

This commit is contained in:
mitsuha
2022-09-02 15:59:24 +08:00
parent 8adc00a944
commit 14a3cdff41
10 changed files with 89 additions and 116 deletions

View File

@@ -80,7 +80,6 @@ export const FileSystem = () => {
if (apiSupported && !selected) { if (apiSupported && !selected) {
return ( return (
<>
<MuiSnackbar <MuiSnackbar
anchorOrigin={{ vertical: 'top', horizontal: 'right' }} anchorOrigin={{ vertical: 'top', horizontal: 'right' }}
open={error} open={error}
@@ -95,19 +94,6 @@ export const FileSystem = () => {
</IconButton> </IconButton>
} }
/> />
<StyledFileSystem
onClick={async () => {
try {
await requestPermission('AFFiNE');
onSelected();
} catch (e) {
onError();
}
}}
>
{t('Sync to Disk')}
</StyledFileSystem>
</>
); );
} }
return null; return null;

View File

@@ -70,9 +70,6 @@ export const LayoutHeader = () => {
<EditorBoardSwitcher /> <EditorBoardSwitcher />
</StyledContainerForEditorBoardSwitcher> </StyledContainerForEditorBoardSwitcher>
</StyledHeaderRoot> </StyledHeaderRoot>
<StyledUnstableTips>
<StyledUnstableTipsText>{warningTips}</StyledUnstableTipsText>
</StyledUnstableTips>
</StyledContainerForHeaderRoot> </StyledContainerForHeaderRoot>
); );
}; };

View File

@@ -2,8 +2,8 @@ import { useFlag } from '@toeverything/datasource/feature-flags';
export const useSettingFlags = () => { export const useSettingFlags = () => {
const booleanFullWidthChecked = useFlag('BooleanFullWidthChecked', false); const booleanFullWidthChecked = useFlag('BooleanFullWidthChecked', false);
const booleanExportWorkspace = useFlag('BooleanExportWorkspace', false); const booleanExportWorkspace = useFlag('BooleanExportAffineDb', true);
const booleanImportWorkspace = useFlag('BooleanImportWorkspace', false); const booleanImportWorkspace = useFlag('BooleanImportAffineDb', true);
const booleanExportHtml = useFlag('BooleanExportHtml', false); const booleanExportHtml = useFlag('BooleanExportHtml', false);
const booleanExportPdf = useFlag('BooleanExportPdf', false); const booleanExportPdf = useFlag('BooleanExportPdf', false);
const booleanExportMarkdown = useFlag('BooleanExportMarkdown', false); const booleanExportMarkdown = useFlag('BooleanExportMarkdown', false);

View File

@@ -145,12 +145,19 @@ export const useSettings = (): SettingItem[] => {
type: 'separator', type: 'separator',
key: 'separator2', key: 'separator2',
}, },
{
type: 'button',
name: t('Clear Workspace'),
key: 'Clear Workspace',
onClick: () => clearWorkspace(workspaceId),
flag: 'booleanClearWorkspace',
},
{ {
type: 'button', type: 'button',
name: t('Import Workspace'), name: t('Import Workspace'),
key: 'Import Workspace', key: 'Import Workspace',
onClick: () => importWorkspace(workspaceId), onClick: () => importWorkspace(workspaceId),
flag: 'booleanImportWorkspace', flag: 'booleanClearWorkspace',
}, },
{ {
type: 'button', type: 'button',
@@ -159,13 +166,6 @@ export const useSettings = (): SettingItem[] => {
onClick: () => exportWorkspace(), onClick: () => exportWorkspace(),
flag: 'booleanExportWorkspace', flag: 'booleanExportWorkspace',
}, },
{
type: 'button',
name: t('Clear Workspace'),
key: 'Clear Workspace',
onClick: () => clearWorkspace(workspaceId),
flag: 'booleanClearWorkspace',
},
]; ];
return filterSettings(settings, settingFlags); return filterSettings(settings, settingFlags);

View File

@@ -6,8 +6,12 @@ export const importWorkspace = (workspaceId: string) => {
window.client window.client
.inspector() .inspector()
.load() .load()
.then(() => { .then(status => {
if (status) {
if (window.confirm('Your currently open data will be lost.')) {
window.location.href = `/${workspaceId}/`; window.location.href = `/${workspaceId}/`;
}
}
}); });
}; };

View File

@@ -39,7 +39,7 @@ async function _getCurrentToken() {
const _enabled = { const _enabled = {
demo: [], demo: [],
AFFiNE: ['sqlite'], AFFiNE: ['idb'],
} as any; } as any;
async function _getBlockDatabase( async function _getBlockDatabase(

View File

@@ -36,7 +36,7 @@ export class UserConfig extends ServiceBaseClass {
} }
const db = await this.database.getDatabase(workspace); const db = await this.database.getDatabase(workspace);
const newPage = await db.get('page'); const newPage = await db.get_named_block('start-page');
await this.get_dependency(PageTree).addPage(workspace, newPage.id); await this.get_dependency(PageTree).addPage(workspace, newPage.id);
await this.addRecentPage(workspace, userId, newPage.id); await this.addRecentPage(workspace, userId, newPage.id);

View File

@@ -357,7 +357,7 @@ export class BlockClient<
* @param name block name * @param name block name
* @returns block instance * @returns block instance
*/ */
private async get_named_block( public async get_named_block(
name: string, name: string,
options?: { workspace?: boolean } options?: { workspace?: boolean }
): Promise<BaseBlock<B, C>> { ): Promise<BaseBlock<B, C>> {

View File

@@ -324,17 +324,18 @@ export class YjsAdapter implements AsyncDatabaseAdapter<YjsContentOperation> {
const binary = encodeStateAsUpdate(this._doc); const binary = encodeStateAsUpdate(this._doc);
saveAs( saveAs(
new Blob([binary]), new Blob([binary]),
`affine_workspace_${new Date().toDateString()}.apk` `affine_workspace_${new Date().toDateString()}.affine`
); );
}, },
load: async () => { load: async () => {
try {
const handles = await window.showOpenFilePicker({ const handles = await window.showOpenFilePicker({
types: [ types: [
{ {
description: 'AFFiNE Package', description: 'AFFiNE Package',
accept: { accept: {
// eslint-disable-next-line @typescript-eslint/naming-convention // eslint-disable-next-line @typescript-eslint/naming-convention
'application/affine': ['.apk'], 'application/affine': ['.affine'],
}, },
}, },
], ],
@@ -371,6 +372,11 @@ export class YjsAdapter implements AsyncDatabaseAdapter<YjsContentOperation> {
await update_check; await update_check;
} }
console.log('load success'); console.log('load success');
return true;
} catch (err) {
return false;
}
}, },
parse: () => this._doc.toJSON(), parse: () => this._doc.toJSON(),
// eslint-disable-next-line @typescript-eslint/naming-convention // eslint-disable-next-line @typescript-eslint/naming-convention

View File

@@ -74,14 +74,13 @@ const _useUserAndSpacesForFreeLogin = () => {
if (location.pathname.startsWith('/local')) { if (location.pathname.startsWith('/local')) {
navigate('/local'); navigate('/local');
} else { } else {
navigate('/demo'); navigate(`/${BRAND_ID}`);
} }
setLoading(false); setLoading(false);
} }
}, []); }, []);
useEffect(() => { useEffect(() => {
if (localTrigger) {
setUser({ setUser({
photo: '', photo: '',
id: BRAND_ID, id: BRAND_ID,
@@ -89,26 +88,7 @@ const _useUserAndSpacesForFreeLogin = () => {
nickname: BRAND_ID, nickname: BRAND_ID,
email: '', email: '',
}); });
} else { }, [setUser]);
if (location.pathname.startsWith('/local')) {
setUser({
photo: '',
id: 'local',
username: 'local',
nickname: 'local',
email: '',
});
} else {
setUser({
photo: '',
id: 'demo',
username: 'demo',
nickname: 'demo',
email: '',
});
}
}
}, [localTrigger, location, setLoading, setUser]);
const currentSpaceId: string | undefined = useMemo(() => user?.id, [user]); const currentSpaceId: string | undefined = useMemo(() => user?.id, [user]);