mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-18 23:07:02 +08:00
refactor(core): remove jump once (#6733)
Previously, we marked `jumpOnce: true` on `doc.meta` to open a specific doc after creating a new workspace. This pr removes `jumpOnce` and directly jumps to the specific doc URL. This PR also fixes an error when opening the all-page page, because the all-page page scans the jumpOnce attribute of all docs, and the code in it will fail on damaged data.
This commit is contained in:
@@ -48,7 +48,7 @@ export const Component = () => {
|
||||
const list = useLiveData(workspacesService.list.workspaces$);
|
||||
const listIsLoading = useLiveData(workspacesService.list.isLoading$);
|
||||
|
||||
const { openPage } = useNavigateHelper();
|
||||
const { openPage, jumpToPage } = useNavigateHelper();
|
||||
const [searchParams] = useSearchParams();
|
||||
|
||||
const createOnceRef = useRef(false);
|
||||
@@ -61,9 +61,15 @@ export const Component = () => {
|
||||
WorkspaceFlavour.AFFINE_CLOUD,
|
||||
'AFFiNE Cloud'
|
||||
)
|
||||
.then(workspace => openPage(workspace.id, WorkspaceSubPath.ALL))
|
||||
.then(({ meta, defaultDocId }) => {
|
||||
if (defaultDocId) {
|
||||
jumpToPage(meta.id, defaultDocId);
|
||||
} else {
|
||||
openPage(meta.id, WorkspaceSubPath.ALL);
|
||||
}
|
||||
})
|
||||
.catch(err => console.error('Failed to create cloud workspace', err));
|
||||
}, [openPage, workspacesService]);
|
||||
}, [jumpToPage, openPage, workspacesService]);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (!navigating) {
|
||||
@@ -114,9 +120,16 @@ export const Component = () => {
|
||||
useEffect(() => {
|
||||
setCreating(true);
|
||||
createFirstAppData(workspacesService)
|
||||
.then(workspaceMeta => {
|
||||
if (workspaceMeta) {
|
||||
openPage(workspaceMeta.id, WorkspaceSubPath.ALL);
|
||||
.then(createdWorkspace => {
|
||||
if (createdWorkspace) {
|
||||
if (createdWorkspace.defaultPageId) {
|
||||
jumpToPage(
|
||||
createdWorkspace.meta.id,
|
||||
createdWorkspace.defaultPageId
|
||||
);
|
||||
} else {
|
||||
openPage(createdWorkspace.meta.id, WorkspaceSubPath.ALL);
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
@@ -125,7 +138,7 @@ export const Component = () => {
|
||||
.finally(() => {
|
||||
setCreating(false);
|
||||
});
|
||||
}, [openPage, workspacesService]);
|
||||
}, [jumpToPage, openPage, workspacesService]);
|
||||
|
||||
if (navigating || creating) {
|
||||
return <WorkspaceFallback></WorkspaceFallback>;
|
||||
|
||||
@@ -4,11 +4,10 @@ import {
|
||||
VirtualizedPageList,
|
||||
} from '@affine/core/components/page-list';
|
||||
import { useBlockSuiteDocMeta } from '@affine/core/hooks/use-block-suite-page-meta';
|
||||
import { useNavigateHelper } from '@affine/core/hooks/use-navigate-helper';
|
||||
import { performanceRenderLogger } from '@affine/core/shared';
|
||||
import type { Filter } from '@affine/env/filter';
|
||||
import { useService, WorkspaceService } from '@toeverything/infra';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useState } from 'react';
|
||||
|
||||
import { ViewBodyIsland, ViewHeaderIsland } from '../../../modules/workbench';
|
||||
import { EmptyPageList } from '../page-list-empty';
|
||||
@@ -59,25 +58,5 @@ export const AllPage = () => {
|
||||
export const Component = () => {
|
||||
performanceRenderLogger.info('AllPage');
|
||||
|
||||
const currentWorkspace = useService(WorkspaceService).workspace;
|
||||
const navigateHelper = useNavigateHelper();
|
||||
|
||||
useEffect(() => {
|
||||
function checkJumpOnce() {
|
||||
for (const [pageId] of currentWorkspace.docCollection.docs) {
|
||||
const page = currentWorkspace.docCollection.getDoc(pageId);
|
||||
if (page && page.meta?.jumpOnce) {
|
||||
currentWorkspace.docCollection.meta.setDocMeta(page.id, {
|
||||
jumpOnce: false,
|
||||
});
|
||||
navigateHelper.jumpToPage(currentWorkspace.id, pageId);
|
||||
}
|
||||
}
|
||||
}
|
||||
checkJumpOnce();
|
||||
return currentWorkspace.docCollection.slots.docUpdated.on(checkJumpOnce)
|
||||
.dispose;
|
||||
}, [currentWorkspace.docCollection, currentWorkspace.id, navigateHelper]);
|
||||
|
||||
return <AllPage />;
|
||||
};
|
||||
|
||||
@@ -325,14 +325,6 @@ export const DetailPage = ({ pageId }: { pageId: string }): ReactElement => {
|
||||
};
|
||||
}, [currentWorkspace, pageId]);
|
||||
|
||||
const jumpOnce = useLiveData(doc?.meta$.map(meta => meta.jumpOnce));
|
||||
|
||||
useEffect(() => {
|
||||
if (jumpOnce) {
|
||||
doc?.record.setMeta({ jumpOnce: false });
|
||||
}
|
||||
}, [doc?.record, jumpOnce]);
|
||||
|
||||
const isInTrash = useLiveData(doc?.meta$.map(meta => meta.trash));
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user