mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
Refactor api requests and components out of pages
This commit is contained in:
37
components/BeerIndex/Pagination.tsx
Normal file
37
components/BeerIndex/Pagination.tsx
Normal file
@@ -0,0 +1,37 @@
|
||||
import { useRouter } from 'next/router';
|
||||
import { FC } from 'react';
|
||||
|
||||
interface PaginationProps {
|
||||
pageNum: number;
|
||||
pageCount: number;
|
||||
}
|
||||
|
||||
const Pagination: FC<PaginationProps> = ({ pageCount, pageNum }) => {
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<div className="btn-group">
|
||||
<button
|
||||
className="btn"
|
||||
disabled={pageNum <= 1}
|
||||
onClick={async () =>
|
||||
router.push({ pathname: '/beers', query: { page_num: pageNum - 1 } })
|
||||
}
|
||||
>
|
||||
«
|
||||
</button>
|
||||
<button className="btn">Page {pageNum}</button>
|
||||
<button
|
||||
className="btn"
|
||||
disabled={pageNum >= pageCount}
|
||||
onClick={async () =>
|
||||
router.push({ pathname: '/beers', query: { page_num: pageNum + 1 } })
|
||||
}
|
||||
>
|
||||
»
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Pagination;
|
||||
Reference in New Issue
Block a user