From fec929dfee038de2635972cdd157da379e0b401e Mon Sep 17 00:00:00 2001 From: Adorian Doran Date: Mon, 23 Feb 2026 12:21:07 +0200 Subject: [PATCH] ui/list & grid view: refactor --- .../src/widgets/collections/Pagination.tsx | 2 +- .../collections/legacy/ListOrGridView.tsx | 103 +++++++++--------- 2 files changed, 53 insertions(+), 52 deletions(-) diff --git a/apps/client/src/widgets/collections/Pagination.tsx b/apps/client/src/widgets/collections/Pagination.tsx index f42b477e88..256d3a39f9 100644 --- a/apps/client/src/widgets/collections/Pagination.tsx +++ b/apps/client/src/widgets/collections/Pagination.tsx @@ -9,7 +9,7 @@ import Button from "../react/Button"; import "./Pagination.css"; import clsx from "clsx"; -interface PaginationContext { +export interface PaginationContext { className?: string; page: number; setPage: Dispatch>; diff --git a/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx b/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx index 9f95fdd635..c6f869c844 100644 --- a/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx +++ b/apps/client/src/widgets/collections/legacy/ListOrGridView.tsx @@ -13,13 +13,13 @@ import { useImperativeSearchHighlighlighting, useNoteLabel, useNoteLabelBoolean, import Icon from "../../react/Icon"; import NoteLink from "../../react/NoteLink"; import { ViewModeProps } from "../interface"; -import { Pager, usePagination } from "../Pagination"; +import { Pager, usePagination, PaginationContext } from "../Pagination"; import { filterChildNotes, useFilteredNoteIds } from "./utils"; import { JSX } from "preact/jsx-runtime"; import { clsx } from "clsx"; import ActionButton from "../../react/ActionButton"; import linkContextMenuService from "../../../menus/link_context_menu"; -import { TargetedMouseEvent } from "preact"; +import { ComponentChildren, TargetedMouseEvent } from "preact"; export function ListView({ note, noteIds: unfilteredNoteIds, highlightedTokens }: ViewModeProps<{}>) { const expandDepth = useExpansionDepth(note); @@ -27,32 +27,18 @@ export function ListView({ note, noteIds: unfilteredNoteIds, highlightedTokens } const { pageNotes, ...pagination } = usePagination(note, noteIds); const [ includeArchived ] = useNoteLabelBoolean(note, "includeArchived"); const noteType = useNoteProperty(note, "type"); - const hasCollectionProperties = [ "book", "search" ].includes(noteType ?? ""); - return ( -
- } - /> - - { noteIds.length > 0 &&
- {!hasCollectionProperties && } - - - {pageNotes?.map(childNote => ( - - ))} - - - -
} -
- ); + return + + {pageNotes?.map(childNote => ( + + ))} + + ; } export function GridView({ note, noteIds: unfilteredNoteIds, highlightedTokens }: ViewModeProps<{}>) { @@ -60,32 +46,47 @@ export function GridView({ note, noteIds: unfilteredNoteIds, highlightedTokens } const { pageNotes, ...pagination } = usePagination(note, noteIds); const [ includeArchived ] = useNoteLabelBoolean(note, "includeArchived"); const noteType = useNoteProperty(note, "type"); - const hasCollectionProperties = [ "book", "search" ].includes(noteType ?? ""); - return ( -
- } - /> - -
- {!hasCollectionProperties && } - -
- {pageNotes?.map(childNote => ( - - ))} -
- - -
+ return +
+ {pageNotes?.map(childNote => ( + + ))}
- ); +
+} + +interface NoteListProps { + note: FNote, + viewMode: "list" | "grid-view", + noteIds: string[], + pagination: PaginationContext, + children: ComponentChildren +} + +function NoteList(props: NoteListProps) { + const noteType = useNoteProperty(props.note, "type"); + const hasCollectionProperties = ["book", "search"].includes(noteType ?? ""); + + return
+ } + /> + + {props.noteIds.length > 0 &&
+ {!hasCollectionProperties && } + + {props.children} + + +
} + +
} function ListNoteCard({ note, parentNote, highlightedTokens, currentLevel, expandDepth, includeArchived }: {