Some checks failed
build-images / web (push) Has been cancelled
vision2026-ci / Python SDK resource tests (push) Has been cancelled
build-images / api (push) Has been cancelled
build-images / worker-gpu (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Has been cancelled
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Has been cancelled
codeql / Analyze (javascript-typescript) (push) Has been cancelled
codeql / Analyze (python) (push) Has been cancelled
perf / API hot-path micro-smoke (budgeted) (push) Has been cancelled
perf / Desktop engine crates (release build check) (push) Has been cancelled
vision2026-ci / API phase modules (ruff + pytest) (push) Has been cancelled
vision2026-ci / Alembic upgrade + drift check (push) Has been cancelled
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Has been cancelled
Paid, hosted product at menivor.com, now retired as a company project. Fresh squashed history of the cleaned working tree (secret-scanned, no .env, no customer data, no outreach logs). Built on MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
97 lines
2.5 KiB
TypeScript
97 lines
2.5 KiB
TypeScript
"use client";
|
|
|
|
import * as React from "react";
|
|
import { ChevronLeft, ChevronRight } from "lucide-react";
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
export interface PaginationProps {
|
|
page: number;
|
|
pageCount: number;
|
|
totalItems: number;
|
|
pageSize: number;
|
|
onPageChange: (page: number) => void;
|
|
}
|
|
|
|
/**
|
|
* Client-side pager for a locally-held catalog list. Shows the current window
|
|
* ("N-M of T") and previous/next controls. Page numbers are 1-indexed.
|
|
*/
|
|
export function Pagination({
|
|
page,
|
|
pageCount,
|
|
totalItems,
|
|
pageSize,
|
|
onPageChange,
|
|
}: Readonly<PaginationProps>) {
|
|
if (pageCount <= 1) return null;
|
|
|
|
const first = (page - 1) * pageSize + 1;
|
|
const last = Math.min(page * pageSize, totalItems);
|
|
|
|
return (
|
|
<nav
|
|
className="mt-6 flex items-center justify-between gap-4"
|
|
aria-label="Pagination"
|
|
>
|
|
<p className="text-sm text-muted-foreground">
|
|
<span className="font-medium text-foreground">
|
|
{first}–{last}
|
|
</span>{" "}
|
|
of {totalItems}
|
|
</p>
|
|
<div className="flex items-center gap-2">
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
onClick={() => onPageChange(page - 1)}
|
|
disabled={page <= 1}
|
|
aria-label="Previous page"
|
|
>
|
|
<ChevronLeft className="size-4" aria-hidden /> Prev
|
|
</Button>
|
|
<span className="text-sm tabular-nums text-muted-foreground">
|
|
{page} / {pageCount}
|
|
</span>
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
onClick={() => onPageChange(page + 1)}
|
|
disabled={page >= pageCount}
|
|
aria-label="Next page"
|
|
>
|
|
Next <ChevronRight className="size-4" aria-hidden />
|
|
</Button>
|
|
</div>
|
|
</nav>
|
|
);
|
|
}
|
|
|
|
export interface UsePaginatedResult<T> {
|
|
page: number;
|
|
pageCount: number;
|
|
pageItems: readonly T[];
|
|
setPage: (page: number) => void;
|
|
}
|
|
|
|
/**
|
|
* Derives a stable paginated window over `items`. Resets to page 1 whenever the
|
|
* item count changes (e.g. after a search filter narrows the list).
|
|
*/
|
|
export function usePaginated<T>(
|
|
items: readonly T[],
|
|
pageSize: number,
|
|
): UsePaginatedResult<T> {
|
|
const [page, setPage] = React.useState(1);
|
|
const pageCount = Math.max(1, Math.ceil(items.length / pageSize));
|
|
|
|
React.useEffect(() => {
|
|
setPage(1);
|
|
}, [items.length]);
|
|
|
|
const safePage = Math.min(page, pageCount);
|
|
const start = (safePage - 1) * pageSize;
|
|
const pageItems = items.slice(start, start + pageSize);
|
|
|
|
return { page: safePage, pageCount, pageItems, setPage };
|
|
}
|