mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-26 02:35:58 +08:00
feat(core): add journal search results to bs doc search (#9052)
fix AF-1842
This commit is contained in:
@@ -20,6 +20,7 @@ import {
|
||||
RecentDocsQuickSearchSession,
|
||||
} from '@affine/core/modules/quicksearch';
|
||||
import { ExternalLinksQuickSearchSession } from '@affine/core/modules/quicksearch/impls/external-links';
|
||||
import { JournalsQuickSearchSession } from '@affine/core/modules/quicksearch/impls/journals';
|
||||
import { WorkbenchService } from '@affine/core/modules/workbench';
|
||||
import { isNewTabTrigger } from '@affine/core/utils';
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
@@ -331,7 +332,7 @@ export function patchQuickSearchService(framework: FrameworkProvider) {
|
||||
const QuickSearch = QuickSearchExtension({
|
||||
async openQuickSearch() {
|
||||
let searchResult: QuickSearchResult = null;
|
||||
searchResult = await new Promise(resolve =>
|
||||
searchResult = await new Promise((resolve, reject) =>
|
||||
framework.get(QuickSearchService).quickSearch.show(
|
||||
[
|
||||
framework.get(RecentDocsQuickSearchSession),
|
||||
@@ -339,6 +340,7 @@ export function patchQuickSearchService(framework: FrameworkProvider) {
|
||||
framework.get(DocsQuickSearchSession),
|
||||
framework.get(LinksQuickSearchSession),
|
||||
framework.get(ExternalLinksQuickSearchSession),
|
||||
framework.get(JournalsQuickSearchSession),
|
||||
],
|
||||
result => {
|
||||
if (result === null) {
|
||||
@@ -372,6 +374,18 @@ export function patchQuickSearchService(framework: FrameworkProvider) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.source === 'date-picker') {
|
||||
result.payload
|
||||
.getDocId()
|
||||
.then(docId => {
|
||||
if (docId) {
|
||||
resolve({ docId });
|
||||
}
|
||||
})
|
||||
.catch(reject);
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.source === 'external-link') {
|
||||
const externalUrl = result.payload.url;
|
||||
resolve({ externalUrl });
|
||||
|
||||
@@ -63,13 +63,23 @@ export const DateSelectorDialog = ({
|
||||
>
|
||||
{/* hack the menu positioning using the following fixed anchor */}
|
||||
<div
|
||||
style={{
|
||||
position: 'fixed',
|
||||
left: position[0],
|
||||
top: position[1],
|
||||
width: position[2],
|
||||
height: position[3],
|
||||
}}
|
||||
style={
|
||||
position
|
||||
? {
|
||||
position: 'fixed',
|
||||
left: position[0],
|
||||
top: position[1],
|
||||
width: position[2],
|
||||
height: position[3],
|
||||
}
|
||||
: {
|
||||
position: 'fixed',
|
||||
left: '50%',
|
||||
top: '50%',
|
||||
width: 0,
|
||||
height: 0,
|
||||
}
|
||||
}
|
||||
/>
|
||||
</Menu>
|
||||
);
|
||||
|
||||
@@ -60,7 +60,7 @@ export type WORKSPACE_DIALOG_SCHEMA = {
|
||||
onBeforeConfirm?: (ids: string[], cb: () => void) => void;
|
||||
}) => string[];
|
||||
'date-selector': (props: {
|
||||
position: [number, number, number, number]; // [x, y, width, height]
|
||||
position?: [number, number, number, number]; // [x, y, width, height]
|
||||
onSelect?: (date?: string) => void;
|
||||
}) => string;
|
||||
import: () => {
|
||||
|
||||
110
packages/frontend/core/src/modules/quicksearch/impls/journals.ts
Normal file
110
packages/frontend/core/src/modules/quicksearch/impls/journals.ts
Normal file
@@ -0,0 +1,110 @@
|
||||
import { I18n, i18nTime } from '@affine/i18n';
|
||||
import { DateTimeIcon } from '@blocksuite/icons/rc';
|
||||
import { Entity, LiveData } from '@toeverything/infra';
|
||||
|
||||
import type { WorkspaceDialogService } from '../../dialogs';
|
||||
import type { DocDisplayMetaService } from '../../doc-display-meta';
|
||||
import { type JournalService, suggestJournalDate } from '../../journal';
|
||||
import type { QuickSearchSession } from '../providers/quick-search-provider';
|
||||
import type { QuickSearchGroup } from '../types/group';
|
||||
import type { QuickSearchItem } from '../types/item';
|
||||
|
||||
const group: QuickSearchGroup = {
|
||||
id: 'journals',
|
||||
label: {
|
||||
i18nKey: 'com.affine.cmdk.affine.category.affine.journal',
|
||||
},
|
||||
score: 0,
|
||||
};
|
||||
|
||||
type JournalQuickSearchItem = QuickSearchItem<
|
||||
'date-picker',
|
||||
{ getDocId: () => Promise<string | undefined> }
|
||||
>;
|
||||
|
||||
export class JournalsQuickSearchSession
|
||||
extends Entity
|
||||
implements
|
||||
QuickSearchSession<
|
||||
'date-picker',
|
||||
{ getDocId: () => Promise<string | undefined> }
|
||||
>
|
||||
{
|
||||
constructor(
|
||||
private readonly journalService: JournalService,
|
||||
private readonly dialogService: WorkspaceDialogService,
|
||||
private readonly docDisplayMetaService: DocDisplayMetaService
|
||||
) {
|
||||
super();
|
||||
}
|
||||
|
||||
query$ = new LiveData('');
|
||||
|
||||
items$: LiveData<JournalQuickSearchItem[]> = LiveData.computed(get => {
|
||||
const getDateDocId = (date?: string) => {
|
||||
if (date) {
|
||||
return this.journalService.ensureJournalByDate(date).id;
|
||||
}
|
||||
return undefined;
|
||||
};
|
||||
|
||||
const items: JournalQuickSearchItem[] = [
|
||||
{
|
||||
icon: DateTimeIcon,
|
||||
id: 'journal:pick-a-date',
|
||||
source: 'date-picker',
|
||||
group: group,
|
||||
label: {
|
||||
title: I18n.t('com.affine.cmdk.affine.category.affine.date-picker'),
|
||||
},
|
||||
score: 0,
|
||||
payload: {
|
||||
getDocId: () => {
|
||||
return new Promise(resolve => {
|
||||
const id = this.dialogService.open('date-selector', {
|
||||
onSelect: date => {
|
||||
resolve(getDateDocId(date));
|
||||
this.dialogService.close(id);
|
||||
},
|
||||
});
|
||||
});
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
const query = get(this.query$);
|
||||
const suggestedDate = suggestJournalDate(query);
|
||||
|
||||
if (suggestedDate) {
|
||||
const { dateString, alias } = suggestedDate;
|
||||
const dateDisplay = i18nTime(dateString, {
|
||||
absolute: { accuracy: 'day' },
|
||||
});
|
||||
|
||||
const icon = this.docDisplayMetaService.getJournalIcon(dateString, {
|
||||
type: 'rc',
|
||||
});
|
||||
|
||||
items.unshift({
|
||||
icon,
|
||||
id: 'journal:date-' + dateString,
|
||||
source: 'date-picker',
|
||||
group: group,
|
||||
label: {
|
||||
title: alias ? `${alias}, ${dateDisplay}` : dateDisplay,
|
||||
},
|
||||
score: 0,
|
||||
payload: {
|
||||
getDocId: () => Promise.resolve(getDateDocId(dateString)),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return items;
|
||||
});
|
||||
|
||||
query(query: string) {
|
||||
this.query$.next(query);
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,10 @@ import {
|
||||
} from '@toeverything/infra';
|
||||
|
||||
import { CollectionService } from '../collection';
|
||||
import { WorkspaceDialogService } from '../dialogs';
|
||||
import { DocDisplayMetaService } from '../doc-display-meta/services/doc-display-meta';
|
||||
import { DocsSearchService } from '../docs-search';
|
||||
import { JournalService } from '../journal';
|
||||
import { TagService } from '../tag';
|
||||
import { WorkbenchService } from '../workbench';
|
||||
import { QuickSearch } from './entities/quick-search';
|
||||
@@ -18,6 +20,7 @@ import { CommandsQuickSearchSession } from './impls/commands';
|
||||
import { CreationQuickSearchSession } from './impls/creation';
|
||||
import { DocsQuickSearchSession } from './impls/docs';
|
||||
import { ExternalLinksQuickSearchSession } from './impls/external-links';
|
||||
import { JournalsQuickSearchSession } from './impls/journals';
|
||||
import { LinksQuickSearchSession } from './impls/links';
|
||||
import { RecentDocsQuickSearchSession } from './impls/recent-docs';
|
||||
import { TagsQuickSearchSession } from './impls/tags';
|
||||
@@ -68,5 +71,10 @@ export function configureQuickSearchModule(framework: Framework) {
|
||||
.entity(RecentDocsQuickSearchSession, [
|
||||
RecentDocsService,
|
||||
DocDisplayMetaService,
|
||||
])
|
||||
.entity(JournalsQuickSearchSession, [
|
||||
JournalService,
|
||||
WorkspaceDialogService,
|
||||
DocDisplayMetaService,
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user