mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-09 05:05:52 +08:00
feat: support createPage with title
This commit is contained in:
@@ -14,7 +14,7 @@ export const Footer = (props: { query: string }) => {
|
|||||||
<Command.Item
|
<Command.Item
|
||||||
data-testid="quickSearch-addNewPage"
|
data-testid="quickSearch-addNewPage"
|
||||||
onSelect={async () => {
|
onSelect={async () => {
|
||||||
const pageId = await createPage();
|
const pageId = await createPage({ title: query });
|
||||||
if (pageId) {
|
if (pageId) {
|
||||||
openPage(pageId);
|
openPage(pageId);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ export const usePageHelper = (): EditorHandlers => {
|
|||||||
}
|
}
|
||||||
currentWorkspace.createPage(pageId);
|
currentWorkspace.createPage(pageId);
|
||||||
currentWorkspace.signals.pageAdded.once(addedPageId => {
|
currentWorkspace.signals.pageAdded.once(addedPageId => {
|
||||||
|
currentWorkspace.setPageMeta(addedPageId, { title });
|
||||||
resolve(addedPageId);
|
resolve(addedPageId);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -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 useCurrentPageMeta from '@/hooks/use-current-page-meta';
|
||||||
const StyledEditorContainer = styled('div')(() => {
|
const StyledEditorContainer = styled('div')(() => {
|
||||||
return {
|
return {
|
||||||
height: 'calc(100vh - 60px)',
|
height: 'calc(100vh - 60px)',
|
||||||
@@ -26,6 +27,7 @@ const Page: NextPageWithLayout = () => {
|
|||||||
const editorContainer = useRef<HTMLDivElement>(null);
|
const editorContainer = useRef<HTMLDivElement>(null);
|
||||||
const { createEditor, setEditor, currentPage, currentWorkspace } =
|
const { createEditor, setEditor, currentPage, currentWorkspace } =
|
||||||
useAppState();
|
useAppState();
|
||||||
|
const { title: metaTitle } = useCurrentPageMeta() || {};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const ret = () => {
|
const ret = () => {
|
||||||
@@ -41,7 +43,8 @@ const Page: NextPageWithLayout = () => {
|
|||||||
setEditor?.current?.(editor);
|
setEditor?.current?.(editor);
|
||||||
if (currentPage!.isEmpty) {
|
if (currentPage!.isEmpty) {
|
||||||
const isFirstPage = currentWorkspace?.meta.pageMetas.length === 1;
|
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({
|
const pageId = currentPage!.addBlock({
|
||||||
flavour: 'affine:page',
|
flavour: 'affine:page',
|
||||||
title,
|
title,
|
||||||
|
|||||||
Reference in New Issue
Block a user