Skip to content

Build your personal knowledge base with Trilium Notes

chore(print/list): address review

Elian Doranbe115c74c362
diff --git a/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx b/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx
index 9017c99ba5..749036598c 100644
--- a/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx
+++ b/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx
@@ -11,7 +11,7 @@ import tree from "../../../services/tree";
import link from "../../../services/link";
import { t } from "../../../services/i18n";
import attribute_renderer from "../../../services/attribute_renderer";
-import { useFilteredNoteIds } from "./utils";
+import { filterChildNotes, useFilteredNoteIds } from "./utils";
export function ListView({ note, noteIds: unfilteredNoteIds, highlightedTokens }: ViewModeProps<{}>) {
const [ isExpanded ] = useNoteLabelBoolean(note, "expanded");
@@ -161,14 +161,10 @@ function NoteContent({ note, trim, noChildrenList, highlightedTokens }: { note:
}
function NoteChildren({ note, parentNote, highlightedTokens }: { note: FNote, parentNote: FNote, highlightedTokens: string[] | null | undefined }) {
- const imageLinks = note.getRelations("imageLink");
const [ childNotes, setChildNotes ] = useState<FNote[]>();
useEffect(() => {
- note.getChildNotes().then(childNotes => {
- const filteredChildNotes = childNotes.filter((childNote) => !imageLinks.find((rel) => rel.value === childNote.noteId));
- setChildNotes(filteredChildNotes);
- });
+ filterChildNotes(note).then(setChildNotes);
}, [ note ]);
return childNotes?.map(childNote => <ListNoteCard note={childNote} parentNote={parentNote} highlightedTokens={highlightedTokens} />)
diff --git a/apps/client/src/widgets/collections/legacy/ListPrintView.tsx b/apps/client/src/widgets/collections/legacy/ListPrintView.tsx
index a2b9d53194..77a354d0db 100644
--- a/apps/client/src/widgets/collections/legacy/ListPrintView.tsx
+++ b/apps/client/src/widgets/collections/legacy/ListPrintView.tsx
@@ -1,10 +1,9 @@
import { useEffect, useLayoutEffect, useState } from "preact/hooks";
-import { RawHtmlBlock } from "../../react/RawHtml";
import froca from "../../../services/froca";
import type FNote from "../../../entities/fnote";
import content_renderer from "../../../services/content_renderer";
import type { ViewModeProps } from "../interface";
-import { useFilteredNoteIds } from "./utils";
+import { filterChildNotes, useFilteredNoteIds } from "./utils";
interface NotesWithContent {
note: FNote;
@@ -13,10 +12,11 @@ interface NotesWithContent {
export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady }: ViewModeProps<{}>) {
const noteIds = useFilteredNoteIds(note, unfilteredNoteIds);
- const noteIdsSet = new Set<string>();
const [ notesWithContent, setNotesWithContent ] = useState<NotesWithContent[]>();
useLayoutEffect(() => {
+ const noteIdsSet = new Set<string>();
+
froca.getNotes(noteIds).then(async (notes) => {
const notesWithContent: NotesWithContent[] = [];
@@ -34,9 +34,7 @@ export function ListPrintView({ note, noteIds: unfilteredNoteIds, onReady }: Vie
notesWithContent.push({ note, contentEl });
if (note.hasChildren()) {
- const imageLinks = note.getRelations("imageLink");
- const childNotes = await note.getChildNotes();
- const filteredChildNotes = childNotes.filter((childNote) => !imageLinks.find((rel) => rel.value === childNote.noteId));
+ const filteredChildNotes = await filterChildNotes(note);
for (const childNote of filteredChildNotes) {
await processNote(childNote, depth + 1);
}
@@ -82,7 +80,7 @@ function insertPageTitle(contentEl: HTMLElement, title: string) {
}
function rewriteHeadings(contentEl: HTMLElement, depth: number) {
- const headings = contentEl.querySelectorAll("h1, h2, h3, h4, h5, h6")
+ const headings = contentEl.querySelectorAll("h1, h2, h3, h4, h5, h6");
for (const headingEl of headings) {
const currentLevel = parseInt(headingEl.tagName.substring(1), 10);
const newLevel = Math.min(currentLevel + depth, 6);
diff --git a/apps/client/src/widgets/collections/legacy/utils.ts b/apps/client/src/widgets/collections/legacy/utils.ts
index 6592c9cd9e..6432ce1d2f 100644
--- a/apps/client/src/widgets/collections/legacy/utils.ts
+++ b/apps/client/src/widgets/collections/legacy/utils.ts
@@ -9,5 +9,12 @@ export function useFilteredNoteIds(note: FNote, noteIds: string[]) {
const includedLinks = note ? note.getRelations().filter((rel) => rel.name === "imageLink" || rel.name === "includeNoteLink") : [];
const includedNoteIds = new Set(includedLinks.map((rel) => rel.value));
return noteIds.filter((noteId) => !includedNoteIds.has(noteId) && noteId !== "_hidden");
- }, noteIds);
+ }, [ note, noteIds ]);
+}
+
+export async function filterChildNotes(note: FNote) {
+ const imageLinks = note.getRelations("imageLink");
+ const imageLinkNoteIds = new Set(imageLinks.map(rel => rel.value));
+ const childNotes = await note.getChildNotes();
+ return childNotes.filter((childNote) => !imageLinkNoteIds.has(childNote.noteId));
}