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.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
feat(core): append to today's joruanl via CMDK (#5692)
Cats Juice6b350b17354e
diff --git a/packages/frontend/core/src/components/pure/cmdk/data.tsx b/packages/frontend/core/src/components/pure/cmdk/data.tsxindex 298dcd3b0b..fa305d98e4 100644--- a/packages/frontend/core/src/components/pure/cmdk/data.tsx+++ b/packages/frontend/core/src/components/pure/cmdk/data.tsx@@ -5,7 +5,12 @@ import {} from '@affine/core/hooks/use-block-suite-page-meta';import type { Collection } from '@affine/env/filter';import { useAFFiNEI18N } from '@affine/i18n/hooks';-import { EdgelessIcon, PageIcon, ViewLayersIcon } from '@blocksuite/icons';+import {+ EdgelessIcon,+ PageIcon,+ TodayIcon,+ ViewLayersIcon,+} from '@blocksuite/icons';import type { PageMeta } from '@blocksuite/store';import { Workspace } from '@toeverything/infra';import { getCurrentStore } from '@toeverything/infra/atom';@@ -23,6 +28,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react';import { pageSettingsAtom, recentPageIdsBaseAtom } from '../../../atoms';import { currentPageIdAtom } from '../../../atoms/mode';+import { useJournalHelper } from '../../../hooks/use-journal';import { useNavigateHelper } from '../../../hooks/use-navigate-helper';import { CollectionService } from '../../../modules/collection';import { WorkspaceSubPath } from '../../../shared';@@ -161,6 +167,7 @@ export const usePageCommands = () => {const pageMetaHelper = usePageMetaHelper(workspace.blockSuiteWorkspace);const query = useAtomValue(cmdkQueryAtom);const navigationHelper = useNavigateHelper();+ const journalHelper = useJournalHelper(workspace.blockSuiteWorkspace);const t = useAFFiNEI18N();const [searchTime, setSearchTime] = useState<number>(0);@@ -253,6 +260,24 @@ export const usePageCommands = () => {// check if the pages have exact match. if not, we should show the "create page" commandif (results.every(command => command.originalValue !== query)) {+ results.push({+ id: 'affine:pages:append-to-journal',+ label: t['com.affine.journal.cmdk.append-to-today'](),+ value: 'affine::append-journal' + query, // hack to make the page always showing in the search result+ category: 'affine:creation',+ run: async () => {+ const appendRes = await journalHelper.appendContentToToday(query);+ if (!appendRes) return;+ const { page, blockId } = appendRes;+ navigationHelper.jumpToPageBlock(+ page.workspace.id,+ page.id,+ blockId+ );+ },+ icon: <TodayIcon />,+ });+results.push({id: 'affine:pages:create-page',label: t['com.affine.cmdk.affine.create-new-page-as']({@@ -294,6 +319,7 @@ export const usePageCommands = () => {t,workspace,pages,+ journalHelper,pageHelper,pageMetaHelper,]);diff --git a/packages/frontend/core/src/components/pure/cmdk/not-found.tsx b/packages/frontend/core/src/components/pure/cmdk/not-found.tsxindex fd96315339..0d73a9e2a5 100644--- a/packages/frontend/core/src/components/pure/cmdk/not-found.tsx+++ b/packages/frontend/core/src/components/pure/cmdk/not-found.tsx@@ -7,9 +7,9 @@ import * as styles from './not-found.css';export const NotFoundGroup = () => {const query = useAtomValue(cmdkQueryAtom);- // hack: we know that the filtered count is 2 when there is no result (create page & edgeless)+ // hack: we know that the filtered count is 3 when there is no result (create page & edgeless & append to journal)const renderNoResult =- useCommandState(state => state.filtered.count === 2) || false;+ useCommandState(state => state.filtered.count === 3) || false;if (!renderNoResult) {return null;diff --git a/packages/frontend/core/src/hooks/use-journal.ts b/packages/frontend/core/src/hooks/use-journal.tsindex 8f6a04827a..3a063d0bb2 100644--- a/packages/frontend/core/src/hooks/use-journal.ts+++ b/packages/frontend/core/src/hooks/use-journal.ts@@ -104,6 +104,21 @@ export const useJournalHelper = (workspace: BlockSuiteWorkspace) => {[getJournalDateString]);+ const appendContentToToday = useCallback(+ async (content: string) => {+ if (!content) return;+ const page = getJournalByDate(dayjs().format(JOURNAL_DATE_FORMAT));+ if (!page) return;+ const blockId = page.addBlock(+ 'affine:paragraph',+ { text: new page.Text(content) },+ page.getBlockByFlavour('affine:note')[0].id+ );+ return { page, blockId };+ },+ [getJournalByDate]+ );+return useMemo(() => ({getJournalsByDate,@@ -112,6 +127,7 @@ export const useJournalHelper = (workspace: BlockSuiteWorkspace) => {getLocalizedJournalDateString,isPageJournal,isPageTodayJournal,+ appendContentToToday,}),[getJournalByDate,@@ -120,6 +136,7 @@ export const useJournalHelper = (workspace: BlockSuiteWorkspace) => {getLocalizedJournalDateString,isPageJournal,isPageTodayJournal,+ appendContentToToday,]);};diff --git a/packages/frontend/i18n/src/resources/en.json b/packages/frontend/i18n/src/resources/en.jsonindex bc317d99d2..39943c4d4e 100644--- a/packages/frontend/i18n/src/resources/en.json+++ b/packages/frontend/i18n/src/resources/en.json@@ -1069,5 +1069,6 @@"com.affine.journal.daily-count-updated-empty-tips": "You haven't updated anything yet","com.affine.journal.conflict-show-more": "{{count}} more articles","com.affine.journal.app-sidebar-title": "Journals",+ "com.affine.journal.cmdk.append-to-today": "Append to Journal","com.affine.editor.reference-not-found": "Linked page not found"}