fix: getPage with undefined pageId

This commit is contained in:
alt0
2022-12-22 17:14:40 +08:00
parent c9055befd1
commit c9e4fdf317
2 changed files with 16 additions and 14 deletions
@@ -28,21 +28,23 @@ export const useLoadPage = () => {
return;
}
const page = pageId ? workspace?.getPage(pageId) : null;
if (!page) {
const savedPageId = workspace.meta.pageMetas[0]?.id;
if (savedPageId) {
router.push(`/workspace/${currentWorkspaceId}/${savedPageId}`);
if (page) {
loadPage?.current?.(pageId);
return;
}
const savedPageId = workspace.meta.pageMetas[0]?.id;
if (savedPageId) {
router.push(`/workspace/${currentWorkspaceId}/${savedPageId}`);
return;
}
createPage?.current?.()?.then(async pageId => {
if (!pageId) {
return;
}
createPage?.current?.()?.then(async pageId => {
if (!pageId) {
return;
}
router.push(`/workspace/${currentWorkspaceId}/${pageId}`);
});
}
loadPage?.current?.(pageId);
router.push(`/workspace/${currentWorkspaceId}/${pageId}`);
});
}, [workspace, pageId, loadPage, createPage, router, currentWorkspaceId]);
return currentPage?.pageId === pageId ? currentPage : null;
@@ -78,7 +78,7 @@ export const AppStateProvider = ({ children }: { children?: ReactNode }) => {
if (pageId === currentPage?.pageId) {
return currentPage;
}
const page = currentWorkspace?.getPage(pageId) || null;
const page = (pageId ? currentWorkspace?.getPage(pageId) : null) || null;
setState(state => ({ ...state, currentPage: page }));
return page;
};