mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-17 15:36:50 +00:00
Pagination component
This commit is contained in:
parent
1bb07bd90c
commit
8f9c560706
@ -5,6 +5,7 @@ import AddSite from "@/components/dialogues/AddSite";
|
||||
import Sites from "@/components/cards/Sites";
|
||||
import axios from "axios";
|
||||
import { useEffect, useState } from "react";
|
||||
import Pagination from "@/components/Pagination";
|
||||
|
||||
interface SitesPageProps {
|
||||
username: string;
|
||||
@ -67,13 +68,12 @@ export default function SitesPage({ username, name }: SitesPageProps) {
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="flex justify-center pt-4">
|
||||
<div className="join">
|
||||
<button className="join-item btn" onClick={() => handlePageChange(currentPage - 1)} disabled={currentPage === 1}>«</button>
|
||||
<button className="join-item btn">Page {currentPage}</button>
|
||||
<button className="join-item btn" onClick={() => handlePageChange(currentPage + 1)} disabled={currentPage === Math.ceil(total / itemPerPage)}>»</button>
|
||||
</div>
|
||||
</div>
|
||||
<Pagination
|
||||
currentPage={currentPage}
|
||||
totalItems={total}
|
||||
itemsPerPage={itemPerPage}
|
||||
onPageChange={handlePageChange}
|
||||
/>
|
||||
</main>
|
||||
</Sidebar>
|
||||
)
|
||||
|
||||
35
components/Pagination.tsx
Normal file
35
components/Pagination.tsx
Normal file
@ -0,0 +1,35 @@
|
||||
export default function Pagination({
|
||||
currentPage,
|
||||
totalItems,
|
||||
itemsPerPage,
|
||||
onPageChange
|
||||
}: {
|
||||
currentPage: number;
|
||||
totalItems: number;
|
||||
itemsPerPage: number;
|
||||
onPageChange: (page: number) => void;
|
||||
}) {
|
||||
const totalPages = Math.ceil(totalItems / itemsPerPage);
|
||||
|
||||
return (
|
||||
<div className="flex justify-center pt-4">
|
||||
<div className="join">
|
||||
<button
|
||||
className="join-item btn"
|
||||
onClick={() => onPageChange(currentPage - 1)}
|
||||
disabled={currentPage === 1}
|
||||
>
|
||||
«
|
||||
</button>
|
||||
<button className="join-item btn">Page {currentPage}</button>
|
||||
<button
|
||||
className="join-item btn"
|
||||
onClick={() => onPageChange(currentPage + 1)}
|
||||
disabled={currentPage === totalPages}
|
||||
>
|
||||
»
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user