Download web/src/customer-grid/GridPager.tsx from fsanyoto/loopable: direct link, hf CLI and curl.
- Browser
- Download file 2.61 kB
-
https://huggingface.co/spaces/fsanyoto/loopable/resolve/main/web/src/customer-grid/GridPager.tsx
- Command line
-
hf download hf://spaces/fsanyoto/loopable/web/src/customer-grid/GridPager.tsx
-
curl -L -o GridPager.tsx https://huggingface.co/spaces/fsanyoto/loopable/resolve/main/web/src/customer-grid/GridPager.tsx
2.61 kB
| /** | |
| * ⭐⭐ HOTFIX 2026-09-23 — the read-through grid's pager. | |
| * | |
| * Owner, verbatim: *"I want fucking either pagination or next page and only load 50 at a time to | |
| * be fucking back."* This revokes SDLC 62 R3 (virtualise only). A read-through table holds ONE | |
| * page of `size` rows; Previous and Next move it. `total` is the server's count of everything the | |
| * predicate matches, so every row stays reachable and the count is never `rows.length`. | |
| */ | |
| export function pageLabel(offset: number, size: number, total: number): string { | |
| if (total <= 0) return "No records"; | |
| const from = Math.min(total, offset + 1); | |
| const to = Math.min(total, offset + size); | |
| return `${from.toLocaleString()} to ${to.toLocaleString()} of ${total.toLocaleString()}`; | |
| } | |
| export function GridPager({ | |
| offset, | |
| size, | |
| sizes, | |
| total, | |
| pending, | |
| onPage, | |
| onSize, | |
| itemsLabel = "Rows", | |
| totalKnown = true, | |
| hasNextPage, | |
| }: { | |
| offset: number; | |
| size: number; | |
| /** HOTFIX 2026-09-24: the page-size choices, on the same line as Previous / Next. */ | |
| sizes: readonly number[]; | |
| total: number; | |
| pending: boolean; | |
| onPage: (offset: number) => void; | |
| onSize: (size: number) => void; | |
| itemsLabel?: "Rows" | "Items"; | |
| totalKnown?: boolean; | |
| hasNextPage?: boolean; | |
| }) { | |
| const pages = Math.max(1, Math.ceil(total / size)); | |
| const page = Math.min(pages, Math.floor(offset / size) + 1); | |
| const hasPrev = offset > 0; | |
| const hasNext = hasNextPage ?? offset + size < total; | |
| return ( | |
| <nav className="cg-pager" aria-label="Pages" aria-busy={pending || undefined}> | |
| <button | |
| type="button" | |
| className="cg-pager-btn" | |
| disabled={!hasPrev} | |
| onClick={() => onPage(Math.max(0, offset - size))} | |
| > | |
| Previous | |
| </button> | |
| <span className="cg-pager-label"> | |
| {totalKnown ? pageLabel(offset, size, total) : total === 0 ? "No records on this page" : | |
| `${total.toLocaleString()} ${total === 1 ? "record" : "records"} on this page`} | |
| {totalKnown && <span className="cg-pager-page">Page {page.toLocaleString()} of {pages.toLocaleString()}</span>} | |
| </span> | |
| <button | |
| type="button" | |
| className="cg-pager-btn" | |
| disabled={!hasNext} | |
| onClick={() => onPage(offset + size)} | |
| > | |
| Next | |
| </button> | |
| <label className="cg-pager-size"> | |
| <span>{itemsLabel} per page</span> | |
| <select value={size} onChange={(e) => onSize(Number(e.currentTarget.value))}> | |
| {sizes.map((n) => ( | |
| <option key={n} value={n}>{n}</option> | |
| ))} | |
| </select> | |
| </label> | |
| </nav> | |
| ); | |
| } | |