Make table page size a configurable setting, not a hardcoded 20
Pagination just landed hardcoded to 20 rows everywhere; add a way to change that instead of leaving it fixed for every table in the app. pageSize joins dateFormat/timeFormat on the existing display settings object (server-side default 20, 5-500 range enforced by the PUT schema) rather than becoming its own settings section, since it's the same kind of thing -- an admin-configured, globally-applied display preference read by every signed-in role via the already-public GET /api/settings/display endpoint, same as the date/time format already works. Renamed the "Date & Time" settings tab/page/route to "Display" (still just one component, now covering both date/time format and table pagination) since its scope no longer matches the old name -- kept Settings.tsx's usual pattern of one page per concern rather than adding a second, oddly-scoped tab just for one number field. New web/src/utils/pageSize.ts mirrors utils/date.ts's existing module-level "set once at startup, read anywhere without prop- drilling" pattern; usePagination()'s pageSize parameter now defaults to getPageSize() instead of a literal 20, evaluated fresh on every call so it picks up a saved change without touching any of the ten pages already using the hook. Verified server-side against a temp SQLite DB: pageSize defaults to 20, a partial update sets it without disturbing dateFormat/timeFormat and vice versa, and it persists across a fresh settings read. Also checked the default-parameter mechanics directly (re-evaluates the global value on every call rather than capturing it once, and an explicit override still wins). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7bf9b03839
commit
b40234a557
10 files changed
+180
-123
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { useMemo, useState } from "react";
|
||||
import { getPageSize } from "../utils/pageSize";
|
||||
|
||||
/**
|
||||
* Client-side pagination over an already-fetched array. Purely a display
|
||||
@@ -10,8 +11,11 @@ import { useMemo, useState } from "react";
|
||||
* integration, a filter that shrinks the result set) can never strand the
|
||||
* view on a page that no longer exists — no caller-side "reset page on
|
||||
* filter change" wiring required.
|
||||
*
|
||||
* Defaults to the app-wide "rows per page" setting (Settings → Display) —
|
||||
* pass an explicit pageSize only to override it for one specific table.
|
||||
*/
|
||||
export function usePagination<T>(items: T[] | null | undefined, pageSize = 20) {
|
||||
export function usePagination<T>(items: T[] | null | undefined, pageSize = getPageSize()) {
|
||||
const [page, setPage] = useState(0);
|
||||
|
||||
const totalCount = items?.length ?? 0;
|
||||
|
||||
Reference in new issue
Block a user