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
chore(react/collections/list): display children recursively
Elian Doranc2a5f437fd8d
diff --git a/apps/client/src/widgets/collections/legacy/ListView.tsx b/apps/client/src/widgets/collections/legacy/ListView.tsxindex f6873aabfe..f28f8c2bbe 100644--- a/apps/client/src/widgets/collections/legacy/ListView.tsx+++ b/apps/client/src/widgets/collections/legacy/ListView.tsx@@ -55,7 +55,10 @@ function NoteCard({ note, expand }: { note: FNote, expand?: boolean }) {<Icon className="note-icon" icon={note.getIcon()} /><NoteLink notePath={notePath} noPreview showNotePath={isSearch} />- <NoteContent note={note} />+ {isExpanded && <>+ <NoteContent note={note} />+ <NoteChildren note={note} />+ </>}</h5></div>)@@ -80,6 +83,20 @@ function NoteContent({ note, trim }: { note: FNote, trim?: boolean }) {return <div ref={contentRef} className="note-book-content" />;}+function NoteChildren({ note }: { note: FNote}) {+ 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);+ });+ }, [ note ]);++ return childNotes?.map(childNote => <NoteCard note={childNote} />)+}+function usePagination(note: FNote, noteIds: string[]) {const [ page, setPage ] = useState(1);const [ pageNotes, setPageNotes ] = useState<FNote[]>();diff --git a/apps/client/src/widgets/view_widgets/list_or_grid_view.ts b/apps/client/src/widgets/view_widgets/list_or_grid_view.tsindex c61859f096..b028fbe42c 100644--- a/apps/client/src/widgets/view_widgets/list_or_grid_view.ts+++ b/apps/client/src/widgets/view_widgets/list_or_grid_view.ts@@ -127,8 +127,6 @@ class ListOrGridView extends ViewMode<{}> {return;}- const $expander = $card.find("> .note-book-header .note-expander");-if ((this.viewType === "grid")) {$card.append(await this.renderNoteContent(note));}@@ -148,18 +146,6 @@ class ListOrGridView extends ViewMode<{}> {});}}-- if (this.viewType === "list") {- const imageLinks = note.getRelations("imageLink");-- const childNotes = (await note.getChildNotes()).filter((childNote) => !imageLinks.find((rel) => rel.value === childNote.noteId));-- for (const childNote of childNotes) {- $content.append(await this.renderNote(childNote));- }- }-- return $content;}}