From 5f73532d62d66deb589addadb7a468226fa15348 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 30 Aug 2025 19:11:12 +0300 Subject: [PATCH] chore(react/collections): fix expand state when switching notes --- .../widgets/collections/legacy/ListView.tsx | 3 + .../widgets/view_widgets/list_or_grid_view.ts | 61 ------------------- 2 files changed, 3 insertions(+), 61 deletions(-) delete mode 100644 apps/client/src/widgets/view_widgets/list_or_grid_view.ts diff --git a/apps/client/src/widgets/collections/legacy/ListView.tsx b/apps/client/src/widgets/collections/legacy/ListView.tsx index eb3ea1de0..9893bdd51 100644 --- a/apps/client/src/widgets/collections/legacy/ListView.tsx +++ b/apps/client/src/widgets/collections/legacy/ListView.tsx @@ -59,6 +59,9 @@ function ListNoteCard({ note, parentNote, expand, highlightedTokens }: { note: F const [ isExpanded, setExpanded ] = useState(expand); const notePath = getNotePath(parentNote, note); + // Reset expand state if switching to another note. + useEffect(() => setExpanded(expand), [ note ]); + return (
{ - private $noteList: JQuery; - - private filteredNoteIds!: string[]; - private page?: number; - private pageSize?: number; - private highlightRegex?: RegExp | null; - - async renderList() { - if (this.filteredNoteIds.length === 0 || !this.page || !this.pageSize) { - this.$noteList.hide(); - return; - } - - const highlightedTokens = this.parentNote.highlightedTokens || []; - if (highlightedTokens.length > 0) { - const regex = highlightedTokens.map((token) => utils.escapeRegExp(token)).join("|"); - - this.highlightRegex = new RegExp(regex, "gi"); - } else { - this.highlightRegex = null; - } - - this.$noteList.show(); - - return this.$noteList; - } - - async renderNote(note: FNote, expand: boolean = false) { - if (this.highlightRegex) { - const Mark = new (await import("mark.js")).default($card.find(".note-book-title")[0]); - Mark.markRegExp(this.highlightRegex, { - element: "span", - className: "ck-find-result" - }); - } - } - - async renderNoteContent(note: FNote) { - try { - if (this.highlightRegex) { - const Mark = new (await import("mark.js")).default($renderedContent[0]); - Mark.markRegExp(this.highlightRegex, { - element: "span", - className: "ck-find-result" - }); - } - } - } -} - -export default ListOrGridView;