diff --git a/libs/components/editor-blocks/src/blocks/group/group-menu/MainMenu.tsx b/libs/components/editor-blocks/src/blocks/group/group-menu/MainMenu.tsx index 92aa53566e..43b819aabe 100644 --- a/libs/components/editor-blocks/src/blocks/group/group-menu/MainMenu.tsx +++ b/libs/components/editor-blocks/src/blocks/group/group-menu/MainMenu.tsx @@ -82,7 +82,7 @@ const GroupMenuWrapper = ({ content={ - + {/**/} { // // Closed beta period temporarily // filterSorterFlag && ( diff --git a/libs/components/layout/src/header/LayoutHeader.tsx b/libs/components/layout/src/header/LayoutHeader.tsx index 9619c97c84..c9e7b7b8da 100644 --- a/libs/components/layout/src/header/LayoutHeader.tsx +++ b/libs/components/layout/src/header/LayoutHeader.tsx @@ -14,7 +14,7 @@ import { import { useTranslation } from 'react-i18next'; import { EditorBoardSwitcher } from './EditorBoardSwitcher'; -import { FileSystem, fsApiSupported } from './FileSystem'; +import { fsApiSupported } from './FileSystem'; import { CurrentPageTitle } from './Title'; export const LayoutHeader = () => { @@ -44,7 +44,6 @@ export const LayoutHeader = () => { - {t('Share')}
{ - - {warningTips} - ); }; diff --git a/libs/components/layout/src/header/PageSettingPortal.tsx b/libs/components/layout/src/header/PageSettingPortal.tsx index 9defcf754d..115b5c95fd 100644 --- a/libs/components/layout/src/header/PageSettingPortal.tsx +++ b/libs/components/layout/src/header/PageSettingPortal.tsx @@ -58,8 +58,6 @@ function PageSettingPortal() { const navigate = useNavigate(); const { user } = useUserAndSpaces(); const BooleanFullWidthChecked = useFlag('BooleanFullWidthChecked', false); - const BooleanExportWorkspace = useFlag('BooleanExportWorkspace', false); - const BooleanImportWorkspace = useFlag('BooleanImportWorkspace', false); const BooleanExportHtml = useFlag('BooleanExportHtml', false); const BooleanExportPdf = useFlag('BooleanExportPdf', false); const BooleanExportMarkdown = useFlag('BooleanExportMarkdown', false); @@ -217,18 +215,14 @@ function PageSettingPortal() { /> )} - {BooleanImportWorkspace && ( - - )} - {BooleanExportWorkspace && ( - - )} + +

Last edited by {user && user.nickname} diff --git a/libs/components/layout/src/settings-sidebar/Settings/use-setting-flags.ts b/libs/components/layout/src/settings-sidebar/Settings/use-setting-flags.ts index e0a7fb697c..532417de03 100644 --- a/libs/components/layout/src/settings-sidebar/Settings/use-setting-flags.ts +++ b/libs/components/layout/src/settings-sidebar/Settings/use-setting-flags.ts @@ -2,8 +2,6 @@ import { useFlag } from '@toeverything/datasource/feature-flags'; export const useSettingFlags = () => { const booleanFullWidthChecked = useFlag('BooleanFullWidthChecked', false); - const booleanExportWorkspace = useFlag('BooleanExportWorkspace', false); - const booleanImportWorkspace = useFlag('BooleanImportWorkspace', false); const booleanExportHtml = useFlag('BooleanExportHtml', false); const booleanExportPdf = useFlag('BooleanExportPdf', false); const booleanExportMarkdown = useFlag('BooleanExportMarkdown', false); @@ -11,8 +9,6 @@ export const useSettingFlags = () => { return { booleanFullWidthChecked, - booleanExportWorkspace, - booleanImportWorkspace, booleanExportHtml, booleanExportPdf, booleanExportMarkdown, diff --git a/libs/components/layout/src/settings-sidebar/Settings/use-settings.ts b/libs/components/layout/src/settings-sidebar/Settings/use-settings.ts index dfd8918c49..53b075db74 100644 --- a/libs/components/layout/src/settings-sidebar/Settings/use-settings.ts +++ b/libs/components/layout/src/settings-sidebar/Settings/use-settings.ts @@ -145,26 +145,24 @@ export const useSettings = (): SettingItem[] => { type: 'separator', key: 'separator2', }, + { + type: 'button', + name: t('Clear Workspace'), + key: 'Clear Workspace', + onClick: () => clearWorkspace(workspaceId), + flag: 'booleanClearWorkspace', + }, { type: 'button', name: t('Import Workspace'), key: 'Import Workspace', - onClick: () => importWorkspace(workspaceId), - flag: 'booleanImportWorkspace', + onClick: () => importWorkspace(), }, { type: 'button', name: t('Export Workspace'), key: 'Export Workspace', onClick: () => exportWorkspace(), - flag: 'booleanExportWorkspace', - }, - { - type: 'button', - name: t('Clear Workspace'), - key: 'Clear Workspace', - onClick: () => clearWorkspace(workspaceId), - flag: 'booleanClearWorkspace', }, ]; diff --git a/libs/components/layout/src/settings-sidebar/Settings/util/inspector-workspace.ts b/libs/components/layout/src/settings-sidebar/Settings/util/inspector-workspace.ts index ee851dc90c..c1edd95c65 100644 --- a/libs/components/layout/src/settings-sidebar/Settings/util/inspector-workspace.ts +++ b/libs/components/layout/src/settings-sidebar/Settings/util/inspector-workspace.ts @@ -1,14 +1,15 @@ /** * @deprecated debugging method, deprecated */ -export const importWorkspace = (workspaceId: string) => { - //@ts-ignore - window.client - .inspector() - .load() - .then(() => { - window.location.href = `/${workspaceId}/`; - }); +export const importWorkspace = async () => { + if (window.confirm('Your currently open data will be lost.')) { + //@ts-ignore + const status = await window.client.inspector().load(); + + if (status) { + window.location.reload(); + } + } }; /** diff --git a/libs/datasource/db-service/src/services/database/index.ts b/libs/datasource/db-service/src/services/database/index.ts index 3d70345f0f..dbbe23bb9e 100644 --- a/libs/datasource/db-service/src/services/database/index.ts +++ b/libs/datasource/db-service/src/services/database/index.ts @@ -39,7 +39,7 @@ async function _getCurrentToken() { const _enabled = { demo: [], - AFFiNE: ['sqlite'], + AFFiNE: ['idb'], } as any; async function _getBlockDatabase( diff --git a/libs/datasource/db-service/src/services/workspace/user-config.ts b/libs/datasource/db-service/src/services/workspace/user-config.ts index 5a52581c21..7251659314 100644 --- a/libs/datasource/db-service/src/services/workspace/user-config.ts +++ b/libs/datasource/db-service/src/services/workspace/user-config.ts @@ -36,7 +36,7 @@ export class UserConfig extends ServiceBaseClass { } const db = await this.database.getDatabase(workspace); - const newPage = await db.get('page'); + const newPage = await db.getNamedBlock('start-page'); await this.get_dependency(PageTree).addPage(workspace, newPage.id); await this.addRecentPage(workspace, userId, newPage.id); diff --git a/libs/datasource/jwt/src/index.ts b/libs/datasource/jwt/src/index.ts index e8f3483e23..626e6a3c89 100644 --- a/libs/datasource/jwt/src/index.ts +++ b/libs/datasource/jwt/src/index.ts @@ -357,7 +357,7 @@ export class BlockClient< * @param name block name * @returns block instance */ - private async get_named_block( + public async getNamedBlock( name: string, options?: { workspace?: boolean } ): Promise> { @@ -376,7 +376,7 @@ export class BlockClient< */ public async getWorkspace() { if (!this._root.node) { - this._root.node = await this.get_named_block(this._workspace, { + this._root.node = await this.getNamedBlock(this._workspace, { workspace: true, }); } diff --git a/libs/datasource/jwt/src/yjs/index.ts b/libs/datasource/jwt/src/yjs/index.ts index 7d0f30e4e3..9b6fa3c3d9 100644 --- a/libs/datasource/jwt/src/yjs/index.ts +++ b/libs/datasource/jwt/src/yjs/index.ts @@ -324,53 +324,58 @@ export class YjsAdapter implements AsyncDatabaseAdapter { const binary = encodeStateAsUpdate(this._doc); saveAs( new Blob([binary]), - `affine_workspace_${new Date().toDateString()}.apk` + `affine_workspace_${new Date().toDateString()}.affine` ); }, load: async () => { - const handles = await window.showOpenFilePicker({ - types: [ - { - description: 'AFFiNE Package', - accept: { - // eslint-disable-next-line @typescript-eslint/naming-convention - 'application/affine': ['.apk'], + try { + const handles = await window.showOpenFilePicker({ + types: [ + { + description: 'AFFiNE Package', + accept: { + // eslint-disable-next-line @typescript-eslint/naming-convention + 'application/affine': ['.affine'], + }, }, - }, - ], - }); - const [file] = (await fromEvent(handles)) as File[]; - const binary = await file?.arrayBuffer(); - // await this._provider.idb.clearData(); - const doc = new Doc({ autoLoad: true, shouldLoad: true }); - let updated = 0; - let isUpdated = false; - doc.on('update', () => { - isUpdated = true; - updated += 1; - }); - setInterval(() => { - if (updated > 0) { - updated -= 1; - } - }, 500); - - const update_check = new Promise(resolve => { - const check = async () => { - while (!isUpdated || updated > 0) { - await sleep(); + ], + }); + const [file] = (await fromEvent(handles)) as File[]; + const binary = await file?.arrayBuffer(); + // await this._provider.idb.clearData(); + const doc = new Doc({ autoLoad: true, shouldLoad: true }); + let updated = 0; + let isUpdated = false; + doc.on('update', () => { + isUpdated = true; + updated += 1; + }); + setInterval(() => { + if (updated > 0) { + updated -= 1; } - resolve(); - }; - check(); - }); - // await new IndexedDBProvider(this._provider.idb.name, doc) - // .whenSynced; - if (binary) { - applyUpdate(doc, new Uint8Array(binary)); - await update_check; + }, 500); + + const update_check = new Promise(resolve => { + const check = async () => { + while (!isUpdated || updated > 0) { + await sleep(); + } + resolve(); + }; + check(); + }); + // await new IndexedDBProvider(this._provider.idb.name, doc) + // .whenSynced; + if (binary) { + applyUpdate(doc, new Uint8Array(binary)); + await update_check; + } + + return true; + } catch (err) { + return false; } - console.log('load success'); }, parse: () => this._doc.toJSON(), // eslint-disable-next-line @typescript-eslint/naming-convention diff --git a/libs/datasource/state/src/user.ts b/libs/datasource/state/src/user.ts index 61893471de..063f9f7f04 100644 --- a/libs/datasource/state/src/user.ts +++ b/libs/datasource/state/src/user.ts @@ -71,44 +71,20 @@ const _useUserAndSpacesForFreeLogin = () => { useEffect(() => { if (loading) { - if (location.pathname.startsWith('/local')) { - navigate('/local'); - } else { - navigate('/demo'); - } + navigate(`/${BRAND_ID}`); setLoading(false); } }, []); useEffect(() => { - if (localTrigger) { - setUser({ - photo: '', - id: BRAND_ID, - username: BRAND_ID, - nickname: BRAND_ID, - email: '', - }); - } else { - 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]); + setUser({ + photo: '', + id: BRAND_ID, + username: BRAND_ID, + nickname: BRAND_ID, + email: '', + }); + }, [setUser]); const currentSpaceId: string | undefined = useMemo(() => user?.id, [user]);