feat: support createPage with title

This commit is contained in:
QiShaoXuan
2022-12-29 16:26:01 +08:00
parent a96f5f2aef
commit d70d8f3f1d
3 changed files with 6 additions and 2 deletions
@@ -14,7 +14,7 @@ export const Footer = (props: { query: string }) => {
<Command.Item
data-testid="quickSearch-addNewPage"
onSelect={async () => {
const pageId = await createPage();
const pageId = await createPage({ title: query });
if (pageId) {
openPage(pageId);
}
@@ -46,6 +46,7 @@ export const usePageHelper = (): EditorHandlers => {
}
currentWorkspace.createPage(pageId);
currentWorkspace.signals.pageAdded.once(addedPageId => {
currentWorkspace.setPageMeta(addedPageId, { title });
resolve(addedPageId);
});
});
@@ -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 useCurrentPageMeta from '@/hooks/use-current-page-meta';
const StyledEditorContainer = styled('div')(() => {
return {
height: 'calc(100vh - 60px)',
@@ -26,6 +27,7 @@ const Page: NextPageWithLayout = () => {
const editorContainer = useRef<HTMLDivElement>(null);
const { createEditor, setEditor, currentPage, currentWorkspace } =
useAppState();
const { title: metaTitle } = useCurrentPageMeta() || {};
useEffect(() => {
const ret = () => {
@@ -41,7 +43,8 @@ const Page: NextPageWithLayout = () => {
setEditor?.current?.(editor);
if (currentPage!.isEmpty) {
const isFirstPage = currentWorkspace?.meta.pageMetas.length === 1;
const title = isFirstPage ? 'Welcome to the AFFiNE Alpha' : '';
const title =
metaTitle || isFirstPage ? 'Welcome to the AFFiNE Alpha' : '';
const pageId = currentPage!.addBlock({
flavour: 'affine:page',
title,