mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-28 15:12:19 +03:00
feat(core): set document title when detail page render (#5418)
This commit is contained in:
parent
a6f5a03b8a
commit
6b9f77f511
16
packages/frontend/core/src/hooks/use-global-state.ts
Normal file
16
packages/frontend/core/src/hooks/use-global-state.ts
Normal 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]);
|
||||
}
|
@ -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) => {
|
||||
|
Loading…
Reference in New Issue
Block a user