mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-28 11:53:24 +03:00
fix: listen on title change
This commit is contained in:
parent
c045c35842
commit
746a6d9ab5
@ -16,6 +16,7 @@ import type { NextPageWithLayout } from '../..//_app';
|
||||
import WorkspaceLayout from '@/components/workspace-layout';
|
||||
import { useRouter } from 'next/router';
|
||||
import { usePageHelper } from '@/hooks/use-page-helper';
|
||||
import { Disposable } from '@blocksuite/store/dist/utils/disposable';
|
||||
|
||||
const StyledEditorContainer = styled('div')(() => {
|
||||
return {
|
||||
@ -24,6 +25,8 @@ const StyledEditorContainer = styled('div')(() => {
|
||||
};
|
||||
});
|
||||
|
||||
const firstPageTitle = 'Welcome to AFFiNE Alpha "Abbey Wood"' as const;
|
||||
|
||||
const Page: NextPageWithLayout = () => {
|
||||
const editorContainer = useRef<HTMLDivElement>(null);
|
||||
const { createEditor, setEditor, currentPage, currentWorkspace } =
|
||||
@ -36,6 +39,7 @@ const Page: NextPageWithLayout = () => {
|
||||
node.removeChild(node.firstChild);
|
||||
}
|
||||
};
|
||||
let disposable: Disposable | undefined;
|
||||
|
||||
const editor = createEditor?.current?.(currentPage!);
|
||||
if (editor) {
|
||||
@ -45,11 +49,7 @@ const Page: NextPageWithLayout = () => {
|
||||
const isFirstPage = currentWorkspace?.meta.pageMetas.length === 1;
|
||||
// Can not use useCurrentPageMeta to get new title, cause meta title will trigger rerender, but the second time can not remove title
|
||||
const { title: metaTitle } = currentPage!.meta;
|
||||
const title = metaTitle
|
||||
? metaTitle
|
||||
: isFirstPage
|
||||
? 'Welcome to AFFiNE Alpha "Abbey Wood"'
|
||||
: '';
|
||||
const title = metaTitle ? metaTitle : isFirstPage ? firstPageTitle : '';
|
||||
currentWorkspace?.setPageMeta(currentPage!.id, { title });
|
||||
|
||||
const pageId = currentPage!.addBlock({
|
||||
@ -72,11 +72,17 @@ const Page: NextPageWithLayout = () => {
|
||||
});
|
||||
}
|
||||
currentPage!.resetHistory();
|
||||
disposable = editor.pageBlockModel?.propsUpdated.on(() => {
|
||||
document.title = isFirstPage
|
||||
? firstPageTitle
|
||||
: currentPage?.meta.title || 'Untitled';
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
document.title = currentPage?.meta.title || 'Untitled';
|
||||
return ret;
|
||||
return () => {
|
||||
ret();
|
||||
disposable?.dispose();
|
||||
};
|
||||
}, [currentWorkspace, currentPage, createEditor, setEditor]);
|
||||
|
||||
return (
|
||||
|
Loading…
Reference in New Issue
Block a user