diff --git a/.gitignore b/.gitignore index 029054a0..8ef500b1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ __debug_bin* vendor pb_data main -certimate +./certimate build /docker/data diff --git a/certimate b/certimate new file mode 100755 index 00000000..11a40ee8 Binary files /dev/null and b/certimate differ diff --git a/ui/src/components/certimate/Pagination.tsx b/ui/src/components/certimate/Pagination.tsx new file mode 100644 index 00000000..35eca5a5 --- /dev/null +++ b/ui/src/components/certimate/Pagination.tsx @@ -0,0 +1,90 @@ +import { Button } from "../ui/button"; + +type PaginationProps = { + totalPages: number; + currentPage: number; + onPageChange: (page: number) => void; +}; + +type PageNumber = number | string; + +const Pagination = ({ + totalPages, + currentPage, + onPageChange, +}: PaginationProps) => { + const pageNeighbours = 2; // Number of page numbers to show on either side of the current page + + const getPageNumbers = () => { + const totalNumbers = pageNeighbours * 2 + 3; // total pages to display (left + right neighbours + current + 2 for start and end) + const totalBlocks = totalNumbers + 2; // adding 2 for the start and end page numbers + + if (totalPages > totalBlocks) { + let pages: PageNumber[] = []; + + const leftBound = Math.max(2, currentPage - pageNeighbours); + const rightBound = Math.min(totalPages - 1, currentPage + pageNeighbours); + + const beforeLastPage = totalPages - 1; + + pages = range(leftBound, rightBound); + + if (currentPage > pageNeighbours + 2) { + pages.unshift("..."); + } + if (currentPage < beforeLastPage - pageNeighbours) { + pages.push("..."); + } + + pages.unshift(1); + pages.push(totalPages); + + return pages; + } + + return range(1, totalPages); + }; + + const range = (from: number, to: number, step = 1) => { + let i = from; + const range = []; + + while (i <= to) { + range.push(i); + i += step; + } + + return range; + }; + + const pages = getPageNumbers(); + + return ( +
+ {pages.map((page, index) => { + if (page === "...") { + return ( + + … + + ); + } + + return ( + + ); + })} +
+ ); +}; + +export default Pagination; diff --git a/ui/src/components/ui/pagination.tsx b/ui/src/components/ui/pagination.tsx new file mode 100644 index 00000000..d6b1fcf1 --- /dev/null +++ b/ui/src/components/ui/pagination.tsx @@ -0,0 +1,117 @@ +import * as React from "react"; +import { ChevronLeft, ChevronRight, MoreHorizontal } from "lucide-react"; + +import { cn } from "@/lib/utils"; +import { ButtonProps, buttonVariants } from "@/components/ui/button"; + +const Pagination = ({ className, ...props }: React.ComponentProps<"nav">) => ( +