feat(core): set document title when detail page render (#5418)

This commit is contained in:
Joooye_34 2023-12-27 15:25:26 +00:00
parent a6f5a03b8a
commit 6b9f77f511
No known key found for this signature in database
GPG Key ID: 3645F0B246B8EFC7
2 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,16 @@
import { noop } from 'lodash-es';
import { useEffect } from 'react';
export function useDocumentTitle(newTitle?: string | null) {
useEffect(() => {
if (environment.isDesktop || !newTitle) {
return noop;
}
const oldTitle = document.title;
document.title = newTitle;
return () => {
document.title = oldTitle;
};
}, [newTitle]);
}

View File

@ -35,6 +35,7 @@ import { PageDetailEditor } from '../../../components/page-detail-editor';
import { TrashPageFooter } from '../../../components/pure/trash-page-footer';
import { TopTip } from '../../../components/top-tip';
import { useRegisterBlocksuiteEditorCommands } from '../../../hooks/affine/use-register-blocksuite-editor-commands';
import { useDocumentTitle } from '../../../hooks/use-global-state';
import { useNavigateHelper } from '../../../hooks/use-navigate-helper';
import { performanceRenderLogger } from '../../../shared';
import { PageNotFound } from '../../404';
@ -114,6 +115,7 @@ const DetailPageImpl = memo(function DetailPageImpl({ page }: { page: Page }) {
const mode = useAtomValue(currentModeAtom);
const setPageMode = useSetAtom(setPageModeAtom);
useRegisterBlocksuiteEditorCommands(currentPageId, mode);
useDocumentTitle(pageMeta?.title ? `${pageMeta.title} · AFFiNE` : null);
const onLoad = useCallback(
(page: Page, editor: AffineEditorContainer) => {