mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-15 05:37:32 +00:00
fix(core): journal display on cmdk (#5723)

This commit is contained in:
@@ -4,6 +4,7 @@ import {
|
|||||||
useBlockSuitePageMeta,
|
useBlockSuitePageMeta,
|
||||||
usePageMetaHelper,
|
usePageMetaHelper,
|
||||||
} from '@affine/core/hooks/use-block-suite-page-meta';
|
} from '@affine/core/hooks/use-block-suite-page-meta';
|
||||||
|
import { useGetBlockSuiteWorkspacePageTitle } from '@affine/core/hooks/use-block-suite-workspace-page-title';
|
||||||
import { useJournalHelper } from '@affine/core/hooks/use-journal';
|
import { useJournalHelper } from '@affine/core/hooks/use-journal';
|
||||||
import { CollectionService } from '@affine/core/modules/collection';
|
import { CollectionService } from '@affine/core/modules/collection';
|
||||||
import { WorkspaceSubPath } from '@affine/core/shared';
|
import { WorkspaceSubPath } from '@affine/core/shared';
|
||||||
@@ -97,25 +98,33 @@ export const pageToCommand = (
|
|||||||
page: PageMeta,
|
page: PageMeta,
|
||||||
store: ReturnType<typeof getCurrentStore>,
|
store: ReturnType<typeof getCurrentStore>,
|
||||||
navigationHelper: ReturnType<typeof useNavigateHelper>,
|
navigationHelper: ReturnType<typeof useNavigateHelper>,
|
||||||
|
getPageTitle: ReturnType<typeof useGetBlockSuiteWorkspacePageTitle>,
|
||||||
|
isPageJournal: (pageId: string) => boolean,
|
||||||
t: ReturnType<typeof useAFFiNEI18N>,
|
t: ReturnType<typeof useAFFiNEI18N>,
|
||||||
workspace: Workspace,
|
workspace: Workspace,
|
||||||
label?: {
|
subTitle?: string,
|
||||||
title: string;
|
|
||||||
subTitle?: string;
|
|
||||||
},
|
|
||||||
blockId?: string
|
blockId?: string
|
||||||
): CMDKCommand => {
|
): CMDKCommand => {
|
||||||
const pageMode = store.get(pageSettingsAtom)?.[page.id]?.mode;
|
const pageMode = store.get(pageSettingsAtom)?.[page.id]?.mode;
|
||||||
|
|
||||||
const title = page.title || t['Untitled']();
|
const title = getPageTitle(page.id) || t['Untitled']();
|
||||||
const commandLabel = label || {
|
const commandLabel = {
|
||||||
title: title,
|
title: title,
|
||||||
|
subTitle: subTitle,
|
||||||
};
|
};
|
||||||
|
|
||||||
// hack: when comparing, the part between >>> and <<< will be ignored
|
// hack: when comparing, the part between >>> and <<< will be ignored
|
||||||
// adding this patch so that CMDK will not complain about duplicated commands
|
// adding this patch so that CMDK will not complain about duplicated commands
|
||||||
const id = category + '.' + page.id;
|
const id = category + '.' + page.id;
|
||||||
|
|
||||||
|
const icon = isPageJournal(page.id) ? (
|
||||||
|
<TodayIcon />
|
||||||
|
) : pageMode === 'edgeless' ? (
|
||||||
|
<EdgelessIcon />
|
||||||
|
) : (
|
||||||
|
<PageIcon />
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
id,
|
id,
|
||||||
label: commandLabel,
|
label: commandLabel,
|
||||||
@@ -130,7 +139,7 @@ export const pageToCommand = (
|
|||||||
}
|
}
|
||||||
return navigationHelper.jumpToPage(workspace.id, page.id);
|
return navigationHelper.jumpToPage(workspace.id, page.id);
|
||||||
},
|
},
|
||||||
icon: pageMode === 'edgeless' ? <EdgelessIcon /> : <PageIcon />,
|
icon: icon,
|
||||||
timestamp: page.updatedDate,
|
timestamp: page.updatedDate,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -146,6 +155,10 @@ export const usePageCommands = () => {
|
|||||||
const navigationHelper = useNavigateHelper();
|
const navigationHelper = useNavigateHelper();
|
||||||
const journalHelper = useJournalHelper(workspace.blockSuiteWorkspace);
|
const journalHelper = useJournalHelper(workspace.blockSuiteWorkspace);
|
||||||
const t = useAFFiNEI18N();
|
const t = useAFFiNEI18N();
|
||||||
|
const getPageTitle = useGetBlockSuiteWorkspacePageTitle(
|
||||||
|
workspace.blockSuiteWorkspace
|
||||||
|
);
|
||||||
|
const { isPageJournal } = useJournalHelper(workspace.blockSuiteWorkspace);
|
||||||
|
|
||||||
const [searchTime, setSearchTime] = useState<number>(0);
|
const [searchTime, setSearchTime] = useState<number>(0);
|
||||||
|
|
||||||
@@ -174,6 +187,8 @@ export const usePageCommands = () => {
|
|||||||
page,
|
page,
|
||||||
store,
|
store,
|
||||||
navigationHelper,
|
navigationHelper,
|
||||||
|
getPageTitle,
|
||||||
|
isPageJournal,
|
||||||
t,
|
t,
|
||||||
workspace
|
workspace
|
||||||
);
|
);
|
||||||
@@ -198,10 +213,6 @@ export const usePageCommands = () => {
|
|||||||
|
|
||||||
const subTitle = resultValues.find(result => result.space === page.id)
|
const subTitle = resultValues.find(result => result.space === page.id)
|
||||||
?.content;
|
?.content;
|
||||||
const label = {
|
|
||||||
title: page.title || t['Untitled'](), // Used to ensure that a title exists
|
|
||||||
subTitle: subTitle || '',
|
|
||||||
};
|
|
||||||
|
|
||||||
const blockId = reverseMapping.get(page.id);
|
const blockId = reverseMapping.get(page.id);
|
||||||
|
|
||||||
@@ -210,9 +221,11 @@ export const usePageCommands = () => {
|
|||||||
page,
|
page,
|
||||||
store,
|
store,
|
||||||
navigationHelper,
|
navigationHelper,
|
||||||
|
getPageTitle,
|
||||||
|
isPageJournal,
|
||||||
t,
|
t,
|
||||||
workspace,
|
workspace,
|
||||||
label,
|
subTitle,
|
||||||
blockId
|
blockId
|
||||||
);
|
);
|
||||||
return command;
|
return command;
|
||||||
@@ -276,6 +289,8 @@ export const usePageCommands = () => {
|
|||||||
recentPages,
|
recentPages,
|
||||||
store,
|
store,
|
||||||
navigationHelper,
|
navigationHelper,
|
||||||
|
getPageTitle,
|
||||||
|
isPageJournal,
|
||||||
t,
|
t,
|
||||||
workspace,
|
workspace,
|
||||||
pages,
|
pages,
|
||||||
|
|||||||
@@ -2,8 +2,9 @@ import { assertExists } from '@blocksuite/global/utils';
|
|||||||
import type { Workspace } from '@blocksuite/store';
|
import type { Workspace } from '@blocksuite/store';
|
||||||
import type { Atom } from 'jotai';
|
import type { Atom } from 'jotai';
|
||||||
import { atom, useAtomValue } from 'jotai';
|
import { atom, useAtomValue } from 'jotai';
|
||||||
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
import { useJournalInfoHelper } from './use-journal';
|
import { useJournalHelper, useJournalInfoHelper } from './use-journal';
|
||||||
|
|
||||||
const weakMap = new WeakMap<Workspace, Map<string, Atom<string>>>();
|
const weakMap = new WeakMap<Workspace, Map<string, Atom<string>>>();
|
||||||
|
|
||||||
@@ -44,3 +45,20 @@ export function useBlockSuiteWorkspacePageTitle(
|
|||||||
);
|
);
|
||||||
return localizedJournalDate || title;
|
return localizedJournalDate || title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This hook is NOT reactive to the page title change
|
||||||
|
export function useGetBlockSuiteWorkspacePageTitle(
|
||||||
|
blockSuiteWorkspace: Workspace
|
||||||
|
) {
|
||||||
|
const { getLocalizedJournalDateString } =
|
||||||
|
useJournalHelper(blockSuiteWorkspace);
|
||||||
|
return useCallback(
|
||||||
|
(pageId: string) => {
|
||||||
|
return (
|
||||||
|
getLocalizedJournalDateString(pageId) ||
|
||||||
|
blockSuiteWorkspace.getPage(pageId)?.meta.title
|
||||||
|
);
|
||||||
|
},
|
||||||
|
[blockSuiteWorkspace, getLocalizedJournalDateString]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user