-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
140 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
"use client"; | ||
|
||
import Link from "next/link"; | ||
|
||
type PaginationProps = { | ||
currentPage: number; | ||
totalItems: number; | ||
itemsPerPage: number; | ||
path: string; | ||
}; | ||
|
||
export default function Pagination({ | ||
currentPage, | ||
totalItems, | ||
itemsPerPage, | ||
path, | ||
}: PaginationProps) { | ||
const totalPages = Math.ceil(totalItems / itemsPerPage); | ||
|
||
if (totalPages <= 1) { | ||
return null; | ||
} | ||
|
||
const pageNumbers = []; | ||
const maxVisiblePages = 4; // Adjust this number to show more or fewer page buttons | ||
|
||
let startPage = Math.max(1, currentPage - Math.floor(maxVisiblePages / 2)); | ||
let endPage = Math.min(totalPages, startPage + maxVisiblePages - 1); | ||
|
||
if (endPage - startPage + 1 < maxVisiblePages) { | ||
startPage = Math.max(1, endPage - maxVisiblePages + 1); | ||
} | ||
|
||
for (let i = startPage; i <= endPage; i++) { | ||
pageNumbers.push(i); | ||
} | ||
console.log("currentPage", pageNumbers); | ||
|
||
return ( | ||
<div className="flex justify-center mt-4"> | ||
<div className="join"> | ||
{pageNumbers.map((number) => ( | ||
<Link | ||
key={number} | ||
href={`${path}?page=${number}&limit=${itemsPerPage}`} | ||
className={`join-item btn ${ | ||
number === currentPage ? "btn-active" : "" | ||
}`} | ||
> | ||
{number} | ||
</Link> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters