Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix: hook `useRecentlyViewed` (#1430)

Himself65b3659d6a95b8
diff --git a/apps/web/src/atoms/index.ts b/apps/web/src/atoms/index.ts
index 5aea3eaae9..ebfee8ae06 100644
--- a/apps/web/src/atoms/index.ts
+++ b/apps/web/src/atoms/index.ts
@@ -60,7 +60,7 @@ export const workspacesAtom = atom<Promise<RemWorkspace[]>>(async get => {
return workspaces.filter(workspace => workspace !== null) as RemWorkspace[];
});
-type View = { title: string; id: string; mode: 'page' | 'edgeless' };
+type View = { id: string; mode: 'page' | 'edgeless' };
export type WorkspaceRecentViews = Record<string, View[]>;
diff --git a/apps/web/src/components/pure/quick-search-modal/Results.tsx b/apps/web/src/components/pure/quick-search-modal/Results.tsx
index 1f0d5e91bd..112fc5a582 100644
--- a/apps/web/src/components/pure/quick-search-modal/Results.tsx
+++ b/apps/web/src/components/pure/quick-search-modal/Results.tsx
@@ -1,3 +1,4 @@
+import { UNTITLED_WORKSPACE_NAME } from '@affine/env';
import { useTranslation } from '@affine/i18n';
import { EdgelessIcon, PaperIcon } from '@blocksuite/icons';
import { assertExists } from '@blocksuite/store';
@@ -94,18 +95,24 @@ export const Results: React.FC<ResultsProps> = ({
{recentlyViewed.length > 0 && (
<Command.Group heading={t('Recent')}>
{recentlyViewed
- .filter(
- recent =>
- pageList.find(page => recent.id === page.id)?.trash !== true
- )
+ .filter(recent => {
+ const page = pageList.find(page => recent.id === page.id);
+ if (!page) {
+ return false;
+ } else {
+ return page.trash !== true;
+ }
+ })
.map(recent => {
+ const page = pageList.find(page => recent.id === page.id);
+ assertExists(page);
return (
<Command.Item
- key={recent.id}
- value={recent.id}
+ key={page.id}
+ value={page.id}
onSelect={() => {
onClose();
- jumpToPage(blockSuiteWorkspace.id, recent.id);
+ jumpToPage(blockSuiteWorkspace.id, page.id);
}}
>
<StyledListItem>
@@ -114,7 +121,7 @@ export const Results: React.FC<ResultsProps> = ({
) : (
<PaperIcon />
)}
- <span>{recent.title}</span>
+ <span>{page.title || UNTITLED_WORKSPACE_NAME}</span>
</StyledListItem>
</Command.Item>
);
diff --git a/apps/web/src/hooks/__tests__/index.spec.tsx b/apps/web/src/hooks/__tests__/index.spec.tsx
index 205a24075c..dd3c82367b 100644
--- a/apps/web/src/hooks/__tests__/index.spec.tsx
+++ b/apps/web/src/hooks/__tests__/index.spec.tsx
@@ -310,7 +310,6 @@ describe('useRecentlyViewed', () => {
{
id: 'page0',
mode: 'page',
- title: 'Untitled',
},
]);
});
diff --git a/apps/web/src/hooks/affine/use-recent-views.ts b/apps/web/src/hooks/affine/use-recent-views.ts
index 2465262d36..39054d2a1f 100644
--- a/apps/web/src/hooks/affine/use-recent-views.ts
+++ b/apps/web/src/hooks/affine/use-recent-views.ts
@@ -22,7 +22,7 @@ export function useSyncRecentViewsWithRouter(router: NextRouter) {
const [workspace] = useCurrentWorkspace();
const workspaceId = workspace?.id || null;
const blockSuiteWorkspace = workspace?.blockSuiteWorkspace || null;
- const pageId = router.query.pageId as string;
+ const pageId = router.query.pageId;
const set = useSetAtom(workspaceRecentViresWriteAtom);
const meta = usePageMeta(blockSuiteWorkspace).find(
meta => meta.id === pageId
@@ -31,7 +31,6 @@ export function useSyncRecentViewsWithRouter(router: NextRouter) {
if (!workspaceId) return;
if (pageId && meta) {
set(workspaceId, {
- title: meta.title || 'Untitled',
id: pageId as string,
mode: meta.mode || 'page',
});