2022-10-17 23:37:01 +08:00
|
|
|
import Link from '@/components/Link';
|
2022-07-17 21:40:41 +08:00
|
|
|
|
2022-10-07 13:55:39 +08:00
|
|
|
interface Props {
|
2022-10-17 23:37:01 +08:00
|
|
|
totalPages: number;
|
|
|
|
currentPage: number;
|
2022-10-07 13:55:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function Pagination({ totalPages, currentPage }: Props) {
|
2022-10-17 23:37:01 +08:00
|
|
|
const prevPage = currentPage - 1 > 0;
|
|
|
|
const nextPage = currentPage + 1 <= totalPages;
|
2022-07-17 21:40:41 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="space-y-2 pt-6 pb-8 md:space-y-5">
|
|
|
|
<nav className="flex justify-between">
|
|
|
|
{!prevPage && (
|
2022-10-17 23:37:01 +08:00
|
|
|
<button
|
|
|
|
className="cursor-auto disabled:opacity-50"
|
|
|
|
disabled={!prevPage}>
|
2022-07-17 21:40:41 +08:00
|
|
|
Previous
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
{prevPage && (
|
2022-10-17 23:37:01 +08:00
|
|
|
<Link
|
|
|
|
href={
|
|
|
|
currentPage - 1 === 1 ? `/blog/` : `/blog/page/${currentPage - 1}`
|
|
|
|
}>
|
2022-10-07 13:55:39 +08:00
|
|
|
<button>Previous</button>
|
2022-07-17 21:40:41 +08:00
|
|
|
</Link>
|
|
|
|
)}
|
|
|
|
<span>
|
|
|
|
{currentPage} of {totalPages}
|
|
|
|
</span>
|
|
|
|
{!nextPage && (
|
2022-10-17 23:37:01 +08:00
|
|
|
<button
|
|
|
|
className="cursor-auto disabled:opacity-50"
|
|
|
|
disabled={!nextPage}>
|
2022-07-17 21:40:41 +08:00
|
|
|
Next
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
{nextPage && (
|
|
|
|
<Link href={`/blog/page/${currentPage + 1}`}>
|
2022-10-07 13:55:39 +08:00
|
|
|
<button>Next</button>
|
2022-07-17 21:40:41 +08:00
|
|
|
</Link>
|
|
|
|
)}
|
|
|
|
</nav>
|
|
|
|
</div>
|
2022-10-17 23:37:01 +08:00
|
|
|
);
|
2022-07-17 21:40:41 +08:00
|
|
|
}
|