mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 13:25:12 +00:00
fix(core): improve doc title and icon display (#9755)
Closes: [AF-2132](https://linear.app/affine-design/issue/AF-2132/优化-emoji-title-和-icon-显示)
This commit is contained in:
@@ -91,14 +91,10 @@ export class AtMenuConfigService extends Service {
|
||||
return null;
|
||||
}
|
||||
|
||||
let title = docDisplayMetaService.title$(meta.id, {
|
||||
const title = docDisplayMetaService.title$(meta.id, {
|
||||
reference: true,
|
||||
}).value;
|
||||
|
||||
if (typeof title === 'object' && 'i18nKey' in title) {
|
||||
title = I18n.t(title);
|
||||
}
|
||||
|
||||
if (!fuzzyMatch(title, query)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -40,16 +40,15 @@ interface DocDisplayIconOptions<T extends IconType> {
|
||||
* by default, it will use the `primaryMode$` of the doc.
|
||||
*/
|
||||
mode?: 'edgeless' | 'page';
|
||||
title?: string; // title alias
|
||||
reference?: boolean;
|
||||
referenceToNode?: boolean;
|
||||
hasTitleAlias?: boolean;
|
||||
/**
|
||||
* @default true
|
||||
*/
|
||||
enableEmojiIcon?: boolean;
|
||||
}
|
||||
interface DocDisplayTitleOptions {
|
||||
originalTitle?: string;
|
||||
title?: string; // title alias
|
||||
reference?: boolean;
|
||||
/**
|
||||
@@ -130,24 +129,31 @@ export class DocDisplayMetaService extends Service {
|
||||
const iconSet = icons[options?.type ?? 'rc'];
|
||||
|
||||
return LiveData.computed(get => {
|
||||
const enableEmojiIcon =
|
||||
get(this.featureFlagService.flags.enable_emoji_doc_icon.$) &&
|
||||
options?.enableEmojiIcon !== false;
|
||||
const doc = get(this.docsService.list.doc$(docId));
|
||||
const title = doc ? get(doc.title$) : '';
|
||||
const referenced = !!options?.reference;
|
||||
const titleAlias = referenced ? options?.title : undefined;
|
||||
const originalTitle = doc ? get(doc.title$) : '';
|
||||
const title = titleAlias ?? originalTitle;
|
||||
const mode = doc ? get(doc.primaryMode$) : undefined;
|
||||
const finalMode = options?.mode ?? mode ?? 'page';
|
||||
const referenceToNode = !!(options?.reference && options.referenceToNode);
|
||||
const hasTitleAlias = !!(options?.reference && options?.hasTitleAlias);
|
||||
const referenceToNode = !!(referenced && options.referenceToNode);
|
||||
|
||||
// increases block link priority with title alias
|
||||
if (hasTitleAlias) {
|
||||
return iconSet.AliasIcon;
|
||||
// emoji title
|
||||
if (enableEmojiIcon && title) {
|
||||
const { emoji } = extractEmojiIcon(title);
|
||||
if (emoji) return () => emoji;
|
||||
}
|
||||
|
||||
// increases block link priority
|
||||
if (referenceToNode) {
|
||||
return iconSet.BlockLinkIcon;
|
||||
}
|
||||
// title alias
|
||||
if (titleAlias) return iconSet.AliasIcon;
|
||||
|
||||
// journal icon
|
||||
// link to specified block
|
||||
if (referenceToNode) return iconSet.BlockLinkIcon;
|
||||
|
||||
// link to journal doc
|
||||
const journalDate = this._toDayjs(
|
||||
get(this.journalService.journalDate$(docId))
|
||||
);
|
||||
@@ -155,22 +161,13 @@ export class DocDisplayMetaService extends Service {
|
||||
return this.getJournalIcon(journalDate, options);
|
||||
}
|
||||
|
||||
// reference icon
|
||||
// link to regular doc (reference)
|
||||
if (options?.reference) {
|
||||
return finalMode === 'edgeless'
|
||||
? iconSet.LinkedEdgelessIcon
|
||||
: iconSet.LinkedPageIcon;
|
||||
}
|
||||
|
||||
// emoji icon
|
||||
const enableEmojiIcon =
|
||||
get(this.featureFlagService.flags.enable_emoji_doc_icon.$) &&
|
||||
options?.enableEmojiIcon !== false;
|
||||
if (enableEmojiIcon) {
|
||||
const { emoji } = extractEmojiIcon(title);
|
||||
if (emoji) return () => emoji;
|
||||
}
|
||||
|
||||
// default icon
|
||||
return finalMode === 'edgeless' ? iconSet.EdgelessIcon : iconSet.PageIcon;
|
||||
});
|
||||
@@ -183,14 +180,28 @@ export class DocDisplayMetaService extends Service {
|
||||
options?.enableEmojiIcon !== false;
|
||||
const lng = get(this.i18nService.i18n.currentLanguageKey$);
|
||||
const doc = get(this.docsService.list.doc$(docId));
|
||||
const referenced = !!options?.reference;
|
||||
const titleAlias = referenced ? options?.title : undefined;
|
||||
const originalTitle = doc ? get(doc.title$) : '';
|
||||
const title = titleAlias ?? originalTitle;
|
||||
|
||||
// title alias
|
||||
if (options?.title) {
|
||||
return enableEmojiIcon
|
||||
? extractEmojiIcon(options.title).rest
|
||||
: options.title;
|
||||
// emoji title
|
||||
if (enableEmojiIcon && title) {
|
||||
const { rest } = extractEmojiIcon(title);
|
||||
if (rest) return rest;
|
||||
|
||||
// When the title has only one emoji character,
|
||||
// if it's a journal document, the date should be displayed.
|
||||
const journalDateString = get(this.journalService.journalDate$(docId));
|
||||
if (journalDateString) {
|
||||
return i18nTime(journalDateString, { absolute: { accuracy: 'day' } });
|
||||
}
|
||||
}
|
||||
|
||||
// title alias
|
||||
if (titleAlias) return titleAlias;
|
||||
|
||||
// doc not found
|
||||
if (!doc) {
|
||||
return this.i18nService.i18n.i18next.t(
|
||||
'com.affine.notFoundPage.title',
|
||||
@@ -205,31 +216,16 @@ export class DocDisplayMetaService extends Service {
|
||||
}
|
||||
|
||||
// original title
|
||||
if (options?.originalTitle) return options.originalTitle;
|
||||
|
||||
const docTitle = get(doc.title$);
|
||||
if (originalTitle) return originalTitle;
|
||||
|
||||
// empty title
|
||||
if (!docTitle) {
|
||||
return this.i18nService.i18n.i18next.t('Untitled', { lng });
|
||||
}
|
||||
|
||||
// reference
|
||||
if (options?.reference) return docTitle;
|
||||
|
||||
// emoji icon
|
||||
if (enableEmojiIcon) {
|
||||
return extractEmojiIcon(docTitle).rest;
|
||||
}
|
||||
|
||||
// default
|
||||
return docTitle;
|
||||
return this.i18nService.i18n.i18next.t('Untitled', { lng });
|
||||
});
|
||||
}
|
||||
|
||||
getDocDisplayMeta(docRecord: DocRecord, originalTitle?: string) {
|
||||
getDocDisplayMeta(docRecord: DocRecord) {
|
||||
return {
|
||||
title: this.title$(docRecord.id, { originalTitle }).value,
|
||||
title: this.title$(docRecord.id).value,
|
||||
icon: this.icon$(docRecord.id).value,
|
||||
updatedDate: docRecord.meta$.value.updatedDate,
|
||||
};
|
||||
|
||||
@@ -66,10 +66,7 @@ export class DocsQuickSearchSession
|
||||
)
|
||||
.map(([doc, docRecord]) => {
|
||||
const { title, icon, updatedDate } =
|
||||
this.docDisplayMetaService.getDocDisplayMeta(
|
||||
docRecord,
|
||||
'title' in doc ? doc.title : undefined
|
||||
);
|
||||
this.docDisplayMetaService.getDocDisplayMeta(docRecord);
|
||||
return {
|
||||
id: 'doc:' + docRecord.id,
|
||||
source: 'docs',
|
||||
|
||||
Reference in New Issue
Block a user