mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-18 10:31:50 +08:00
Merge pull request #746 from toeverything/20230123-fix-title
This commit is contained in:
@@ -16,6 +16,7 @@ import type { NextPageWithLayout } from '../..//_app';
|
|||||||
import WorkspaceLayout from '@/components/workspace-layout';
|
import WorkspaceLayout from '@/components/workspace-layout';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import { usePageHelper } from '@/hooks/use-page-helper';
|
import { usePageHelper } from '@/hooks/use-page-helper';
|
||||||
|
import type { Disposable } from '@blocksuite/store';
|
||||||
|
|
||||||
const StyledEditorContainer = styled('div')(() => {
|
const StyledEditorContainer = styled('div')(() => {
|
||||||
return {
|
return {
|
||||||
@@ -24,6 +25,8 @@ const StyledEditorContainer = styled('div')(() => {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const firstPageTitle = 'Welcome to AFFiNE Alpha "Abbey Wood"' as const;
|
||||||
|
|
||||||
const Page: NextPageWithLayout = () => {
|
const Page: NextPageWithLayout = () => {
|
||||||
const editorContainer = useRef<HTMLDivElement>(null);
|
const editorContainer = useRef<HTMLDivElement>(null);
|
||||||
const { createEditor, setEditor, currentPage, currentWorkspace } =
|
const { createEditor, setEditor, currentPage, currentWorkspace } =
|
||||||
@@ -36,20 +39,17 @@ const Page: NextPageWithLayout = () => {
|
|||||||
node.removeChild(node.firstChild);
|
node.removeChild(node.firstChild);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
let disposable: Disposable | undefined;
|
||||||
|
|
||||||
const editor = createEditor?.current?.(currentPage!);
|
const editor = createEditor?.current?.(currentPage!);
|
||||||
|
const isFirstPage = currentWorkspace?.meta.pageMetas.length === 1;
|
||||||
if (editor) {
|
if (editor) {
|
||||||
editorContainer.current?.appendChild(editor);
|
editorContainer.current?.appendChild(editor);
|
||||||
setEditor?.current?.(editor);
|
setEditor?.current?.(editor);
|
||||||
if (currentPage!.isEmpty) {
|
if (currentPage!.isEmpty) {
|
||||||
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
|
// 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 } = currentPage!.meta;
|
||||||
const title = metaTitle
|
const title = metaTitle ? metaTitle : isFirstPage ? firstPageTitle : '';
|
||||||
? metaTitle
|
|
||||||
: isFirstPage
|
|
||||||
? 'Welcome to AFFiNE Alpha "Abbey Wood"'
|
|
||||||
: '';
|
|
||||||
currentWorkspace?.setPageMeta(currentPage!.id, { title });
|
currentWorkspace?.setPageMeta(currentPage!.id, { title });
|
||||||
|
|
||||||
const pageId = currentPage!.addBlock({
|
const pageId = currentPage!.addBlock({
|
||||||
@@ -73,10 +73,16 @@ const Page: NextPageWithLayout = () => {
|
|||||||
}
|
}
|
||||||
currentPage!.resetHistory();
|
currentPage!.resetHistory();
|
||||||
}
|
}
|
||||||
|
disposable = editor.pageBlockModel?.propsUpdated.on(() => {
|
||||||
|
document.title = isFirstPage
|
||||||
|
? firstPageTitle
|
||||||
|
: currentPage?.meta.title || 'Untitled';
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
return () => {
|
||||||
document.title = currentPage?.meta.title || 'Untitled';
|
ret();
|
||||||
return ret;
|
disposable?.dispose();
|
||||||
|
};
|
||||||
}, [currentWorkspace, currentPage, createEditor, setEditor]);
|
}, [currentWorkspace, currentPage, createEditor, setEditor]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user