mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-02 18:09:58 +08:00
fix: icon of page reference node (#7255)
- Use `EdgelessIcon` if linked document mode is edgeless - Update reference icon when document mode changes https://github.com/toeverything/AFFiNE/assets/12724894/40db8930-dd7f-4154-ad0a-b1eea97d23db
This commit is contained in:
@@ -6,14 +6,25 @@ import {
|
|||||||
} from '@affine/core/modules/peek-view';
|
} from '@affine/core/modules/peek-view';
|
||||||
import { WorkbenchLink } from '@affine/core/modules/workbench';
|
import { WorkbenchLink } from '@affine/core/modules/workbench';
|
||||||
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
import { useAFFiNEI18N } from '@affine/i18n/hooks';
|
||||||
import { LinkedPageIcon, TodayIcon } from '@blocksuite/icons/rc';
|
import {
|
||||||
|
LinkedEdgelessIcon,
|
||||||
|
LinkedPageIcon,
|
||||||
|
TodayIcon,
|
||||||
|
} from '@blocksuite/icons/rc';
|
||||||
import type { DocCollection } from '@blocksuite/store';
|
import type { DocCollection } from '@blocksuite/store';
|
||||||
import { useService } from '@toeverything/infra';
|
import {
|
||||||
|
type DocMode,
|
||||||
|
DocsService,
|
||||||
|
LiveData,
|
||||||
|
useLiveData,
|
||||||
|
useService,
|
||||||
|
} from '@toeverything/infra';
|
||||||
import { type PropsWithChildren, useCallback, useRef } from 'react';
|
import { type PropsWithChildren, useCallback, useRef } from 'react';
|
||||||
|
|
||||||
import * as styles from './styles.css';
|
import * as styles from './styles.css';
|
||||||
|
|
||||||
export interface PageReferenceRendererOptions {
|
export interface PageReferenceRendererOptions {
|
||||||
|
docMode: DocMode | null;
|
||||||
pageId: string;
|
pageId: string;
|
||||||
docCollection: DocCollection;
|
docCollection: DocCollection;
|
||||||
pageMetaHelper: ReturnType<typeof useDocMetaHelper>;
|
pageMetaHelper: ReturnType<typeof useDocMetaHelper>;
|
||||||
@@ -22,6 +33,7 @@ export interface PageReferenceRendererOptions {
|
|||||||
}
|
}
|
||||||
// use a function to be rendered in the lit renderer
|
// use a function to be rendered in the lit renderer
|
||||||
export function pageReferenceRenderer({
|
export function pageReferenceRenderer({
|
||||||
|
docMode,
|
||||||
pageId,
|
pageId,
|
||||||
pageMetaHelper,
|
pageMetaHelper,
|
||||||
journalHelper,
|
journalHelper,
|
||||||
@@ -31,7 +43,12 @@ export function pageReferenceRenderer({
|
|||||||
const referencedPage = pageMetaHelper.getDocMeta(pageId);
|
const referencedPage = pageMetaHelper.getDocMeta(pageId);
|
||||||
let title =
|
let title =
|
||||||
referencedPage?.title ?? t['com.affine.editor.reference-not-found']();
|
referencedPage?.title ?? t['com.affine.editor.reference-not-found']();
|
||||||
let icon = <LinkedPageIcon className={styles.pageReferenceIcon} />;
|
let icon =
|
||||||
|
docMode === 'page' ? (
|
||||||
|
<LinkedPageIcon className={styles.pageReferenceIcon} />
|
||||||
|
) : (
|
||||||
|
<LinkedEdgelessIcon className={styles.pageReferenceIcon} />
|
||||||
|
);
|
||||||
const isJournal = isPageJournal(pageId);
|
const isJournal = isPageJournal(pageId);
|
||||||
const localizedJournalDate = getLocalizedJournalDateString(pageId);
|
const localizedJournalDate = getLocalizedJournalDateString(pageId);
|
||||||
if (isJournal && localizedJournalDate) {
|
if (isJournal && localizedJournalDate) {
|
||||||
@@ -61,7 +78,12 @@ export function AffinePageReference({
|
|||||||
const pageMetaHelper = useDocMetaHelper(docCollection);
|
const pageMetaHelper = useDocMetaHelper(docCollection);
|
||||||
const journalHelper = useJournalHelper(docCollection);
|
const journalHelper = useJournalHelper(docCollection);
|
||||||
const t = useAFFiNEI18N();
|
const t = useAFFiNEI18N();
|
||||||
|
|
||||||
|
const docsService = useService(DocsService);
|
||||||
|
const mode$ = LiveData.from(docsService.list.observeMode(pageId), null);
|
||||||
|
const docMode = useLiveData(mode$);
|
||||||
const el = pageReferenceRenderer({
|
const el = pageReferenceRenderer({
|
||||||
|
docMode,
|
||||||
pageId,
|
pageId,
|
||||||
pageMetaHelper,
|
pageMetaHelper,
|
||||||
journalHelper,
|
journalHelper,
|
||||||
|
|||||||
Reference in New Issue
Block a user