fix: cleanup page id in time (#2236)

This commit is contained in:
Himself65 2023-05-04 22:22:11 -05:00 committed by GitHub
parent 1b12972afd
commit f7d1d922fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -2,6 +2,7 @@ import type { EditorContainer } from '@blocksuite/editor';
import type { Page } from '@blocksuite/store';
import { assertExists } from '@blocksuite/store';
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 { useAtomValue, useSetAtom } from 'jotai';
import Head from 'next/head';
@ -34,7 +35,7 @@ export const PageDetailEditor: React.FC<PageDetailEditorProps> = ({
isPreview,
}) => {
const blockSuiteWorkspace = workspace.blockSuiteWorkspace;
const page = blockSuiteWorkspace.getPage(pageId);
const page = useBlockSuiteWorkspacePage(blockSuiteWorkspace, pageId);
if (!page) {
throw new PageNotFoundError(blockSuiteWorkspace, pageId);
}
@ -63,7 +64,7 @@ export const PageDetailEditor: React.FC<PageDetailEditorProps> = ({
style={{
height: 'calc(100% - 52px)',
}}
key={`${workspace.flavour}-${workspace.id}-${[pageId]}`}
key={`${workspace.flavour}-${workspace.id}-${pageId}`}
mode={isPublic ? 'page' : currentMode}
page={page}
onInit={useCallback(

View File

@ -13,6 +13,9 @@ export function useSyncRouterWithCurrentPageId(router: NextRouter) {
if (typeof pageId === 'string') {
console.log('set page id', pageId);
setCurrentPageId(pageId);
} else if (pageId === undefined) {
console.log('cleanup page');
setCurrentPageId(null);
}
}, [router.isReady, router.query.pageId, setCurrentPageId]);
}