mirror of
https://github.com/zadam/trilium.git
synced 2025-11-01 19:05:59 +01:00
chore(react/collections): fix expand state when switching notes
This commit is contained in:
@@ -59,6 +59,9 @@ function ListNoteCard({ note, parentNote, expand, highlightedTokens }: { note: F
|
|||||||
const [ isExpanded, setExpanded ] = useState(expand);
|
const [ isExpanded, setExpanded ] = useState(expand);
|
||||||
const notePath = getNotePath(parentNote, note);
|
const notePath = getNotePath(parentNote, note);
|
||||||
|
|
||||||
|
// Reset expand state if switching to another note.
|
||||||
|
useEffect(() => setExpanded(expand), [ note ]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={`note-book-card no-tooltip-preview ${isExpanded ? "expanded" : ""}`}
|
className={`note-book-card no-tooltip-preview ${isExpanded ? "expanded" : ""}`}
|
||||||
|
|||||||
@@ -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;
|
|
||||||
Reference in New Issue
Block a user