diff --git a/apps/core/src/bootstrap/plugins/setup.ts b/apps/core/src/bootstrap/plugins/setup.ts index 3f563354f2..b836992a52 100644 --- a/apps/core/src/bootstrap/plugins/setup.ts +++ b/apps/core/src/bootstrap/plugins/setup.ts @@ -16,7 +16,7 @@ import { } from '@toeverything/infra/__internal__/plugin'; import { contentLayoutAtom, - currentPageAtom, + currentPageIdAtom, currentWorkspaceAtom, } from '@toeverything/infra/atom'; import { atom } from 'jotai'; @@ -129,7 +129,7 @@ export function createSetup(rootStore: ReturnType) { function createSetupImpl(rootStore: ReturnType) { // clean up plugin windows when switching to other pages - rootStore.sub(currentPageAtom, () => { + rootStore.sub(currentPageIdAtom, () => { rootStore.set(contentLayoutAtom, 'editor'); }); @@ -149,7 +149,7 @@ function createSetupImpl(rootStore: ReturnType) { '@affine/sdk/entry': { rootStore, currentWorkspaceAtom: currentWorkspaceAtom, - currentPageAtom: currentPageAtom, + currentPageIdAtom: currentPageIdAtom, pushLayoutAtom: pushLayoutAtom, deleteLayoutAtom: deleteLayoutAtom, }, diff --git a/packages/infra/src/atom.ts b/packages/infra/src/atom.ts index 5bc57b9e03..601ad31b2a 100644 --- a/packages/infra/src/atom.ts +++ b/packages/infra/src/atom.ts @@ -1,9 +1,9 @@ import type { ExpectedLayout } from '@affine/sdk/entry'; import { assertExists } from '@blocksuite/global/utils'; -import type { Page, Workspace } from '@blocksuite/store'; +import type { Workspace } from '@blocksuite/store'; import { atom, createStore } from 'jotai/vanilla'; -import { getWorkspace, waitForWorkspace } from './__internal__/workspace.js'; +import { getActiveBlockSuiteWorkspaceAtom } from './__internal__/workspace'; // global store let rootStore = createStore(); @@ -24,25 +24,10 @@ export const loadedPluginNameAtom = atom([]); export const currentWorkspaceIdAtom = atom(null); export const currentPageIdAtom = atom(null); export const currentWorkspaceAtom = atom>(async get => { - const currentWorkspaceId = get(currentWorkspaceIdAtom); - assertExists(currentWorkspaceId, 'current workspace id'); - const workspace = getWorkspace(currentWorkspaceId); - await waitForWorkspace(workspace); - return workspace; -}); -export const currentPageAtom = atom>(async get => { - const currentWorkspaceId = get(currentWorkspaceIdAtom); - assertExists(currentWorkspaceId, 'current workspace id'); - const currentPageId = get(currentPageIdAtom); - assertExists(currentPageId, 'current page id'); - const workspace = getWorkspace(currentWorkspaceId); - await waitForWorkspace(workspace); - const page = workspace.getPage(currentPageId); - assertExists(page); - if (!page.loaded) { - await page.waitForLoaded(); - } - return page; + const workspaceId = get(currentWorkspaceIdAtom); + assertExists(workspaceId); + const currentWorkspaceAtom = getActiveBlockSuiteWorkspaceAtom(workspaceId); + return get(currentWorkspaceAtom); }); const contentLayoutBaseAtom = atom('editor');