Skip to content

Build your personal knowledge base with Trilium Notes

chore(react/collections): fix expand state when switching notes

Elian Doran5f73532d62d6
diff --git a/apps/client/src/widgets/collections/legacy/ListView.tsx b/apps/client/src/widgets/collections/legacy/ListView.tsx
index eb3ea1de0d..9893bdd51a 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 (
<div
className={`note-book-card no-tooltip-preview ${isExpanded ? "expanded" : ""}`}
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.ts
deleted file mode 100644
index 2ca6b246ae..0000000000
--- a/apps/client/src/widgets/view_widgets/list_or_grid_view.ts
+++ /dev/null
@@ -1,61 +0,0 @@
-import linkService from "../../services/link.js";
-import contentRenderer from "../../services/content_renderer.js";
-import attributeRenderer from "../../services/attribute_renderer.js";
-import treeService from "../../services/tree.js";
-import utils from "../../services/utils.js";
-import type FNote from "../../entities/fnote.js";
-import ViewMode, { type ViewModeArgs } from "./view_mode.js";
-import { ViewTypeOptions } from "../collections/interface.js";
-
-class ListOrGridView extends ViewMode<{}> {
- private $noteList: JQuery<HTMLElement>;
-
- 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;