From 3f951f98e9efc03e713fbda9869598842c4d751f Mon Sep 17 00:00:00 2001 From: clocko Date: Wed, 24 Jun 2026 16:43:21 +0100 Subject: [PATCH] fix: consolidate duplicate TransactionPagination into single correct implementation --- components/transactions/pagination.tsx | 140 +++++++++++++++---------- 1 file changed, 83 insertions(+), 57 deletions(-) diff --git a/components/transactions/pagination.tsx b/components/transactions/pagination.tsx index 81f3ea2..037fae5 100644 --- a/components/transactions/pagination.tsx +++ b/components/transactions/pagination.tsx @@ -1,67 +1,93 @@ "use client"; -import { cn } from "@/lib/utils"; +import { ChevronLeft, ChevronRight } from "lucide-react"; -interface PaginationProps { - currentPage: number; - totalPages: number; - onPageChange: (page: number) => void; - totalItems: number; - itemsPerPage: number; +interface TransactionPaginationProps { + currentPage: number; + totalPages: number; + onPageChange: (page: number) => void; + totalItems: number; + itemsPerPage: number; } -export function TransactionPagination({ - currentPage, - totalPages, - onPageChange, - totalItems, - itemsPerPage -}: PaginationProps) { - const startItem = ((currentPage - 1) * itemsPerPage) + 1; - const endItem = Math.min(currentPage * itemsPerPage, totalItems); +export function TransactionPagination({ + currentPage, + totalPages, + onPageChange, + totalItems, + itemsPerPage, +}: TransactionPaginationProps) { + const startItem = (currentPage - 1) * itemsPerPage + 1; + const endItem = Math.min(currentPage * itemsPerPage, totalItems); - return ( -
-

- Showing {startItem} to {endItem} of {totalItems} entries -

+ const getVisiblePages = () => { + const delta = 2; + const range = []; + const rangeWithDots = []; -
- + for (let i = Math.max(2, currentPage - delta); i <= Math.min(totalPages - 1, currentPage + delta); i++) { + range.push(i); + } - {/* Simplified page numbers for now */} -
- {[1, 2, 3, 4, 5].map((page) => ( - - ))} - ... -
+ if (currentPage - delta > 2) { + rangeWithDots.push(1, '...'); + } else { + rangeWithDots.push(1); + } - -
-
- ); + rangeWithDots.push(...range); + + if (currentPage + delta < totalPages - 1) { + rangeWithDots.push('...', totalPages); + } else if (totalPages > 1) { + rangeWithDots.push(totalPages); + } + + return rangeWithDots; + }; + + if (totalPages <= 1) return null; + + return ( +
+
+ Showing {startItem} to {endItem} of {totalItems} results +
+ +
+ + + {getVisiblePages().map((page, index) => ( + + ))} + + +
+
+ ); }