fix: cleanup page id in time (#2236)
This commit is contained in:
@@ -2,6 +2,7 @@ import type { EditorContainer } from '@blocksuite/editor';
|
|||||||
import type { Page } from '@blocksuite/store';
|
import type { Page } from '@blocksuite/store';
|
||||||
import { assertExists } from '@blocksuite/store';
|
import { assertExists } from '@blocksuite/store';
|
||||||
import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
|
import { useBlockSuitePageMeta } from '@toeverything/hooks/use-block-suite-page-meta';
|
||||||
|
import { useBlockSuiteWorkspacePage } from '@toeverything/hooks/use-block-suite-workspace-page';
|
||||||
import { useBlockSuiteWorkspacePageTitle } from '@toeverything/hooks/use-block-suite-workspace-page-title';
|
import { useBlockSuiteWorkspacePageTitle } from '@toeverything/hooks/use-block-suite-workspace-page-title';
|
||||||
import { useAtomValue, useSetAtom } from 'jotai';
|
import { useAtomValue, useSetAtom } from 'jotai';
|
||||||
import Head from 'next/head';
|
import Head from 'next/head';
|
||||||
@@ -34,7 +35,7 @@ export const PageDetailEditor: React.FC<PageDetailEditorProps> = ({
|
|||||||
isPreview,
|
isPreview,
|
||||||
}) => {
|
}) => {
|
||||||
const blockSuiteWorkspace = workspace.blockSuiteWorkspace;
|
const blockSuiteWorkspace = workspace.blockSuiteWorkspace;
|
||||||
const page = blockSuiteWorkspace.getPage(pageId);
|
const page = useBlockSuiteWorkspacePage(blockSuiteWorkspace, pageId);
|
||||||
if (!page) {
|
if (!page) {
|
||||||
throw new PageNotFoundError(blockSuiteWorkspace, pageId);
|
throw new PageNotFoundError(blockSuiteWorkspace, pageId);
|
||||||
}
|
}
|
||||||
@@ -63,7 +64,7 @@ export const PageDetailEditor: React.FC<PageDetailEditorProps> = ({
|
|||||||
style={{
|
style={{
|
||||||
height: 'calc(100% - 52px)',
|
height: 'calc(100% - 52px)',
|
||||||
}}
|
}}
|
||||||
key={`${workspace.flavour}-${workspace.id}-${[pageId]}`}
|
key={`${workspace.flavour}-${workspace.id}-${pageId}`}
|
||||||
mode={isPublic ? 'page' : currentMode}
|
mode={isPublic ? 'page' : currentMode}
|
||||||
page={page}
|
page={page}
|
||||||
onInit={useCallback(
|
onInit={useCallback(
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ export function useSyncRouterWithCurrentPageId(router: NextRouter) {
|
|||||||
if (typeof pageId === 'string') {
|
if (typeof pageId === 'string') {
|
||||||
console.log('set page id', pageId);
|
console.log('set page id', pageId);
|
||||||
setCurrentPageId(pageId);
|
setCurrentPageId(pageId);
|
||||||
|
} else if (pageId === undefined) {
|
||||||
|
console.log('cleanup page');
|
||||||
|
setCurrentPageId(null);
|
||||||
}
|
}
|
||||||
}, [router.isReady, router.query.pageId, setCurrentPageId]);
|
}, [router.isReady, router.query.pageId, setCurrentPageId]);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user