Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(collections/list): children are displayed twice for empty notes (closes #7301)
Elian Doran1d95205503e7
diff --git a/apps/client/src/services/content_renderer.ts b/apps/client/src/services/content_renderer.tsindex c5d93fd514..b0a10b8685 100644--- a/apps/client/src/services/content_renderer.ts+++ b/apps/client/src/services/content_renderer.ts@@ -23,6 +23,8 @@ interface Options {tooltip?: boolean;trim?: boolean;imageHasZoom?: boolean;+ /** If enabled, it will prevent the default behavior in which an empty note would display a list of children. */+ noChildrenList?: boolean;}const CODE_MIME_TYPES = new Set(["application/json"]);@@ -42,7 +44,7 @@ async function getRenderedContent(this: {} | { ctx: string }, entity: FNote | FAconst $renderedContent = $('<div class="rendered-content">');if (type === "text" || type === "book") {- await renderText(entity, $renderedContent);+ await renderText(entity, $renderedContent, options);} else if (type === "code") {await renderCode(entity, $renderedContent);} else if (["image", "canvas", "mindMap"].includes(type)) {@@ -114,7 +116,7 @@ async function getRenderedContent(this: {} | { ctx: string }, entity: FNote | FA};}-async function renderText(note: FNote | FAttachment, $renderedContent: JQuery<HTMLElement>) {+async function renderText(note: FNote | FAttachment, $renderedContent: JQuery<HTMLElement>, options: Options = {}) {// entity must be FNoteconst blob = await note.getBlob();@@ -135,7 +137,7 @@ async function renderText(note: FNote | FAttachment, $renderedContent: JQuery<HT}await formatCodeBlocks($renderedContent);- } else if (note instanceof FNote) {+ } else if (note instanceof FNote && !options.noChildrenList) {await renderChildrenList($renderedContent, note);}}diff --git a/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx b/apps/client/src/widgets/collections/legacy/ListOrGridView.tsxindex 274ef21110..db087e8400 100644--- a/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx+++ b/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx@@ -79,7 +79,7 @@ function ListNoteCard({ note, parentNote, expand, highlightedTokens }: { note: F</h5>{isExpanded && <>- <NoteContent note={note} highlightedTokens={highlightedTokens} />+ <NoteContent note={note} highlightedTokens={highlightedTokens} noChildrenList /><NoteChildren note={note} parentNote={parentNote} highlightedTokens={highlightedTokens} /></>}</div>@@ -110,7 +110,11 @@ function GridNoteCard({ note, parentNote, highlightedTokens }: { note: FNote, pa<span ref={titleRef} className="note-book-title">{noteTitle}</span><NoteAttributes note={note} /></h5>- <NoteContent note={note} trim highlightedTokens={highlightedTokens} />+ <NoteContent+ note={note}+ trim+ highlightedTokens={highlightedTokens}+ /></div>)}@@ -126,12 +130,15 @@ function NoteAttributes({ note }: { note: FNote }) {return <span className="note-list-attributes" ref={ref} />}-function NoteContent({ note, trim, highlightedTokens }: { note: FNote, trim?: boolean, highlightedTokens }) {+function NoteContent({ note, trim, noChildrenList, highlightedTokens }: { note: FNote, trim?: boolean, noChildrenList?: boolean, highlightedTokens: string[] | null | undefined }) {const contentRef = useRef<HTMLDivElement>(null);const highlightSearch = useImperativeSearchHighlighlighting(highlightedTokens);useEffect(() => {- content_renderer.getRenderedContent(note, { trim })+ content_renderer.getRenderedContent(note, {+ trim,+ noChildrenList+ }).then(({ $renderedContent, type }) => {if (!contentRef.current) return;contentRef.current.replaceChildren(...$renderedContent);