mirror of
https://github.com/zadam/trilium.git
synced 2025-11-16 21:44:31 +01:00
feat(board/relation): react to column title changes
This commit is contained in:
parent
0c616fecdf
commit
f820c6f23b
@ -1,11 +1,21 @@
|
|||||||
import type { AttachmentRow, EtapiTokenRow, OptionNames } from "@triliumnext/commons";
|
import type { AttachmentRow, EtapiTokenRow, NoteType, OptionNames } from "@triliumnext/commons";
|
||||||
import type { AttributeType } from "../entities/fattribute.js";
|
import type { AttributeType } from "../entities/fattribute.js";
|
||||||
import type { EntityChange } from "../server_types.js";
|
import type { EntityChange } from "../server_types.js";
|
||||||
|
|
||||||
// TODO: Deduplicate with server.
|
// TODO: Deduplicate with server.
|
||||||
|
|
||||||
interface NoteRow {
|
interface NoteRow {
|
||||||
|
blobId: string;
|
||||||
|
dateCreated: string;
|
||||||
|
dateMOdified: string;
|
||||||
isDeleted?: boolean;
|
isDeleted?: boolean;
|
||||||
|
isProtected?: boolean;
|
||||||
|
mime: string;
|
||||||
|
noteId: string;
|
||||||
|
title: string;
|
||||||
|
type: NoteType;
|
||||||
|
utcDateCreated: string;
|
||||||
|
utcDateModified: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Deduplicate with BranchRow from `rows.ts`/
|
// TODO: Deduplicate with BranchRow from `rows.ts`/
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { useEffect, useRef, useState } from "preact/hooks";
|
import { useEffect, useRef, useState } from "preact/hooks";
|
||||||
import link, { ViewScope } from "../../services/link";
|
import link, { ViewScope } from "../../services/link";
|
||||||
import { useImperativeSearchHighlighlighting } from "./hooks";
|
import { useImperativeSearchHighlighlighting, useTriliumEvent } from "./hooks";
|
||||||
|
|
||||||
interface NoteLinkOpts {
|
interface NoteLinkOpts {
|
||||||
className?: string;
|
className?: string;
|
||||||
@ -19,9 +19,11 @@ interface NoteLinkOpts {
|
|||||||
|
|
||||||
export default function NoteLink({ className, notePath, showNotePath, showNoteIcon, style, noPreview, noTnLink, highlightedTokens, title, viewScope, noContextMenu }: NoteLinkOpts) {
|
export default function NoteLink({ className, notePath, showNotePath, showNoteIcon, style, noPreview, noTnLink, highlightedTokens, title, viewScope, noContextMenu }: NoteLinkOpts) {
|
||||||
const stringifiedNotePath = Array.isArray(notePath) ? notePath.join("/") : notePath;
|
const stringifiedNotePath = Array.isArray(notePath) ? notePath.join("/") : notePath;
|
||||||
|
const noteId = stringifiedNotePath.split("/").at(-1);
|
||||||
const ref = useRef<HTMLSpanElement>(null);
|
const ref = useRef<HTMLSpanElement>(null);
|
||||||
const [ jqueryEl, setJqueryEl ] = useState<JQuery<HTMLElement>>();
|
const [ jqueryEl, setJqueryEl ] = useState<JQuery<HTMLElement>>();
|
||||||
const highlightSearch = useImperativeSearchHighlighlighting(highlightedTokens);
|
const highlightSearch = useImperativeSearchHighlighlighting(highlightedTokens);
|
||||||
|
const [ noteTitle, setNoteTitle ] = useState<string>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
link.createLink(stringifiedNotePath, {
|
link.createLink(stringifiedNotePath, {
|
||||||
@ -30,7 +32,7 @@ export default function NoteLink({ className, notePath, showNotePath, showNoteIc
|
|||||||
showNoteIcon,
|
showNoteIcon,
|
||||||
viewScope
|
viewScope
|
||||||
}).then(setJqueryEl);
|
}).then(setJqueryEl);
|
||||||
}, [ stringifiedNotePath, showNotePath, title, viewScope ]);
|
}, [ stringifiedNotePath, showNotePath, title, viewScope, noteTitle ]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!ref.current || !jqueryEl) return;
|
if (!ref.current || !jqueryEl) return;
|
||||||
@ -38,6 +40,16 @@ export default function NoteLink({ className, notePath, showNotePath, showNoteIc
|
|||||||
highlightSearch(ref.current);
|
highlightSearch(ref.current);
|
||||||
}, [ jqueryEl, highlightedTokens ]);
|
}, [ jqueryEl, highlightedTokens ]);
|
||||||
|
|
||||||
|
useTriliumEvent("entitiesReloaded", ({ loadResults }) => {
|
||||||
|
// React to note title changes, but only if the title is not overwritten.
|
||||||
|
if (!title && noteId) {
|
||||||
|
const entityRow = loadResults.getEntityRow("notes", noteId);
|
||||||
|
if (entityRow) {
|
||||||
|
setNoteTitle(entityRow.title);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (style) {
|
if (style) {
|
||||||
jqueryEl?.css(style);
|
jqueryEl?.css(style);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user