Make the pagination buttons better by conditionally rendering based on amount of pages

This commit is contained in:
Gabriel Brown 2024-07-30 10:17:43 -05:00
parent 44497ebe7b
commit 6b80930a86

View File

@ -19,6 +19,7 @@ import {
import { import {
Pagination, Pagination,
PaginationContent, PaginationContent,
PaginationLink,
PaginationItem, PaginationItem,
PaginationNext, PaginationNext,
PaginationPrevious, PaginationPrevious,
@ -117,6 +118,7 @@ const History_Drawer: React.FC<History_Drawer_Props> = ({ user_id }) => {
/> />
</PaginationItem> </PaginationItem>
)} )}
{totalPages > 10 && (
<h3 className="text-center flex flex-row"> <h3 className="text-center flex flex-row">
Page Page
<h3 className="font-bold mx-1"> <h3 className="font-bold mx-1">
@ -127,6 +129,19 @@ const History_Drawer: React.FC<History_Drawer_Props> = ({ user_id }) => {
{totalPages} {totalPages}
</h3> </h3>
</h3> </h3>
)}
{totalPages <= 10 && Array.from({ length: totalPages }).map((_, idx) => (
<PaginationItem key={idx}>
<PaginationLink
href="#"
onClick={(e) => {
e.preventDefault();
handlePageChange(idx + 1);
}}
>{idx + 1}
</PaginationLink>
</PaginationItem>
))}
{page < totalPages && ( {page < totalPages && (
<PaginationItem> <PaginationItem>
<PaginationNext <PaginationNext
@ -146,18 +161,4 @@ const History_Drawer: React.FC<History_Drawer_Props> = ({ user_id }) => {
</DrawerContent> </DrawerContent>
); );
}; };
export default History_Drawer; export default History_Drawer;
// If you want to show all page numbers:
//{Array.from({ length: totalPages }).map((_, idx) => (
//<PaginationItem key={idx}>
//<PaginationLink
//href="#"
//onClick={(e) => {
//e.preventDefault();
//handlePageChange(idx + 1);
//}}
//>{idx + 1}
//</PaginationLink>
//</PaginationItem>
//))}