fix: open non-trash page when open (#2431)

This commit is contained in:
Himself65 2023-05-17 23:22:31 -07:00 committed by GitHub
parent 34ff08b92b
commit d80dae8a89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 1 deletions

View File

@ -84,6 +84,7 @@ export const PageDetailEditor: React.FC<PageDetailEditorProps> = ({
page.workspace.setPageMeta(page.id, {
updatedDate: Date.now(),
});
localStorage.setItem('last_page_id', page.id);
onLoad?.(page, editor);
},
[onLoad, setEditor]

View File

@ -21,13 +21,19 @@ const IndexPageInner = () => {
return;
}
const lastId = localStorage.getItem('last_workspace_id');
const lastPageId = localStorage.getItem('last_page_id');
const targetWorkspace =
(lastId && workspaces.find(({ id }) => id === lastId)) ||
workspaces.at(0);
if (targetWorkspace) {
const nonTrashPages =
targetWorkspace.blockSuiteWorkspace.meta.pageMetas.filter(
({ trash }) => !trash
);
const pageId =
targetWorkspace.blockSuiteWorkspace.meta.pageMetas.at(0)?.id;
nonTrashPages.find(({ id }) => id === lastPageId)?.id ??
nonTrashPages.at(0)?.id;
if (pageId) {
logger.debug('Found target workspace. Jump to page', pageId);
void jumpToPage(targetWorkspace.id, pageId, RouteLogic.REPLACE);