mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-17 22:37:04 +08:00
fix: hook useRecentlyViewed (#1430)
Co-authored-by: JimmFly <yangjinfei001@gmail.com>
This commit is contained in:
@@ -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[]>;
|
||||
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
|
||||
@@ -310,7 +310,6 @@ describe('useRecentlyViewed', () => {
|
||||
{
|
||||
id: 'page0',
|
||||
mode: 'page',
|
||||
title: 'Untitled',
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -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',
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user