refactor: lazy load workspaces (#3091)

(cherry picked from commit 283f0cd263)
This commit is contained in:
Alex Yang
2023-07-07 22:15:27 +08:00
parent e6530f5017
commit 1908d1a213
45 changed files with 446 additions and 750 deletions

View File

@@ -17,7 +17,10 @@ import {
saveWorkspaceToLocalStorage,
} from '@affine/workspace/local/crud';
import { createIndexedDBDownloadProvider } from '@affine/workspace/providers';
import { createEmptyBlockSuiteWorkspace } from '@affine/workspace/utils';
import {
createEmptyBlockSuiteWorkspace,
useStaticBlockSuiteWorkspace,
} from '@affine/workspace/utils';
import { nanoid } from '@blocksuite/store';
import {
@@ -75,13 +78,11 @@ export const LocalAdapter: WorkspaceAdapter<WorkspaceFlavour.LOCAL> = {
Provider: ({ children }) => {
return <>{children}</>;
},
PageDetail: ({ currentWorkspace, currentPageId, onLoadEditor }) => {
const page = currentWorkspace.blockSuiteWorkspace.getPage(currentPageId);
PageDetail: ({ currentWorkspaceId, currentPageId, onLoadEditor }) => {
const workspace = useStaticBlockSuiteWorkspace(currentWorkspaceId);
const page = workspace.getPage(currentPageId);
if (!page) {
throw new PageNotFoundError(
currentWorkspace.blockSuiteWorkspace,
currentPageId
);
throw new PageNotFoundError(workspace, currentPageId);
}
return (
<>
@@ -89,7 +90,7 @@ export const LocalAdapter: WorkspaceAdapter<WorkspaceFlavour.LOCAL> = {
pageId={currentPageId}
onInit={initEmptyPage}
onLoad={onLoadEditor}
workspace={currentWorkspace}
workspace={workspace}
/>
</>
);
@@ -105,14 +106,14 @@ export const LocalAdapter: WorkspaceAdapter<WorkspaceFlavour.LOCAL> = {
);
},
NewSettingsDetail: ({
currentWorkspace,
currentWorkspaceId,
onDeleteWorkspace,
onTransformWorkspace,
}) => {
return (
<NewWorkspaceSettingDetail
onDeleteWorkspace={onDeleteWorkspace}
workspace={currentWorkspace}
workspaceId={currentWorkspaceId}
onTransferWorkspace={onTransformWorkspace}
/>
);