diff --git a/apps/client/src/widgets/collections/legacy/ListOrGridView.css b/apps/client/src/widgets/collections/legacy/ListOrGridView.css index 73c98a5f2..21e60c981 100644 --- a/apps/client/src/widgets/collections/legacy/ListOrGridView.css +++ b/apps/client/src/widgets/collections/legacy/ListOrGridView.css @@ -117,10 +117,6 @@ border: 1px solid transparent; } -.note-list.grid-view .note-expander { - display: none; -} - .note-list.grid-view .note-book-card { max-height: 300px; } diff --git a/apps/client/src/widgets/collections/legacy/ListView.tsx b/apps/client/src/widgets/collections/legacy/ListView.tsx index 550edff60..f6873aabf 100644 --- a/apps/client/src/widgets/collections/legacy/ListView.tsx +++ b/apps/client/src/widgets/collections/legacy/ListView.tsx @@ -1,10 +1,12 @@ -import { useEffect, useMemo, useState } from "preact/hooks"; +import { useEffect, useMemo, useRef, useState } from "preact/hooks"; import FNote from "../../../entities/fnote"; import Icon from "../../react/Icon"; import { ViewModeProps } from "../interface"; -import { useNoteLabel, useNoteLabelBoolean } from "../../react/hooks"; +import { useNoteLabel, useNoteLabelBoolean, useNoteProperty } from "../../react/hooks"; import froca from "../../../services/froca"; import NoteLink from "../../react/NoteLink"; +import "./ListOrGridView.css"; +import content_renderer from "../../../services/content_renderer"; export default function ListView({ note, noteIds }: ViewModeProps) { const [ isExpanded ] = useNoteLabelBoolean(note, "expanded"); @@ -34,6 +36,7 @@ export default function ListView({ note, noteIds }: ViewModeProps) { } function NoteCard({ note, expand }: { note: FNote, expand?: boolean }) { + const [ isExpanded, setExpanded ] = useState(expand); const isSearch = note.type === "search"; const notePath = isSearch ? note.noteId // for search note parent, we want to display a non-search path @@ -41,17 +44,42 @@ function NoteCard({ note, expand }: { note: FNote, expand?: boolean }) { return (
+ setExpanded(!isExpanded)} + /> + +
) } +function NoteContent({ note, trim }: { note: FNote, trim?: boolean }) { + const contentRef = useRef(null); + + useEffect(() => { + content_renderer.getRenderedContent(note, { trim }) + .then(({ $renderedContent, type }) => { + contentRef.current?.replaceChildren(...$renderedContent); + contentRef.current?.classList.add(`type-${type}`); + }) + .catch(e => { + console.warn(`Caught error while rendering note '${note.noteId}' of type '${note.type}'`); + console.error(e); + contentRef.current?.replaceChildren("rendering error"); + }) + }, [ note ]); + + return
; +} + function usePagination(note: FNote, noteIds: string[]) { const [ page, setPage ] = useState(1); const [ pageNotes, setPageNotes ] = useState(); 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 index e533b3562..c61859f09 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 @@ -1,6 +1,5 @@ import linkService from "../../services/link.js"; import contentRenderer from "../../services/content_renderer.js"; -import froca from "../../services/froca.js"; import attributeRenderer from "../../services/attribute_renderer.js"; import treeService from "../../services/tree.js"; import utils from "../../services/utils.js"; @@ -130,22 +129,12 @@ class ListOrGridView extends ViewMode<{}> { const $expander = $card.find("> .note-book-header .note-expander"); - if (expand || this.viewType === "grid") { - $card.addClass("expanded"); - $expander.addClass("bx-chevron-down").removeClass("bx-chevron-right"); - } else { - $card.removeClass("expanded"); - $expander.addClass("bx-chevron-right").removeClass("bx-chevron-down"); - } - - if ((expand || this.viewType === "grid") && $card.find(".note-book-content").length === 0) { + if ((this.viewType === "grid")) { $card.append(await this.renderNoteContent(note)); } } async renderNoteContent(note: FNote) { - const $content = $('
'); - try { const { $renderedContent, type } = await contentRenderer.getRenderedContent(note, { trim: this.viewType === "grid" // for grid only short content is needed @@ -158,14 +147,6 @@ class ListOrGridView extends ViewMode<{}> { className: "ck-find-result" }); } - - $content.append($renderedContent); - $content.addClass(`type-${type}`); - } catch (e) { - console.warn(`Caught error while rendering note '${note.noteId}' of type '${note.type}'`); - console.error(e); - - $content.append("rendering error"); } if (this.viewType === "list") {