Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix: create page with title (#1449)

JimmFlyb23547f4bd07
diff --git a/apps/web/src/components/pure/quick-search-modal/Footer.tsx b/apps/web/src/components/pure/quick-search-modal/Footer.tsx
index 143ddbac81..1887b8212b 100644
--- a/apps/web/src/components/pure/quick-search-modal/Footer.tsx
+++ b/apps/web/src/components/pure/quick-search-modal/Footer.tsx
@@ -1,4 +1,5 @@
import { useTranslation } from '@affine/i18n';
+import type { PageBlockModel } from '@blocksuite/blocks';
import { PlusIcon } from '@blocksuite/icons';
import { assertEquals, nanoid } from '@blocksuite/store';
import { Command } from 'cmdk';
@@ -26,7 +27,6 @@ export const Footer: React.FC<FooterProps> = ({
const { createPage } = useBlockSuiteWorkspaceHelper(blockSuiteWorkspace);
const { t } = useTranslation();
const { jumpToPage } = useRouterHelper(router);
-
return (
<Command.Item
data-testid="quick-search-add-new-page"
@@ -35,7 +35,17 @@ export const Footer: React.FC<FooterProps> = ({
const id = nanoid();
const pageId = await createPage(id, query);
assertEquals(pageId, id);
- jumpToPage(blockSuiteWorkspace.id, pageId);
+ await jumpToPage(blockSuiteWorkspace.id, pageId);
+ if (!query) {
+ return;
+ }
+ const newPage = blockSuiteWorkspace.getPage(pageId);
+ if (newPage) {
+ const block = newPage.getBlockByFlavour(
+ 'affine:page'
+ )[0] as PageBlockModel;
+ block.title.insert(query, 0);
+ }
}}
>
<StyledModalFooterContent>
diff --git a/tests/quick-search.spec.ts b/tests/quick-search.spec.ts
index 3dec9af592..4375cafcf7 100644
--- a/tests/quick-search.spec.ts
+++ b/tests/quick-search.spec.ts
@@ -99,7 +99,7 @@ test.describe('Search and select', () => {
await openQuickSearchByShortcut(page);
await page.keyboard.insertText('test123456');
await page.waitForTimeout(50);
- await assertResultList(page, ["New 'test123456' page"]);
+ await assertResultList(page, ['test123456']);
await page.keyboard.press('Enter');
await page.waitForTimeout(300);
await assertTitle(page, 'test123456');