mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
Rework pagination and cookies
This commit is contained in:
34
components/BeerIndex/BeerIndexPaginationBar.tsx
Normal file
34
components/BeerIndex/BeerIndexPaginationBar.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
import Link from 'next/link';
|
||||
|
||||
import { FC } from 'react';
|
||||
|
||||
interface PaginationProps {
|
||||
pageNum: number;
|
||||
pageCount: number;
|
||||
}
|
||||
|
||||
const BeerIndexPaginationBar: FC<PaginationProps> = ({ pageCount, pageNum }) => {
|
||||
return (
|
||||
<div className="btn-group">
|
||||
<Link
|
||||
className={`btn ${pageNum === 1 ? 'btn-disabled' : ''}`}
|
||||
href={{ pathname: '/beers', query: { page_num: pageNum - 1 } }}
|
||||
scroll={false}
|
||||
prefetch={true}
|
||||
>
|
||||
«
|
||||
</Link>
|
||||
<button className="btn">Page {pageNum}</button>
|
||||
<Link
|
||||
className={`btn ${pageNum === pageCount ? 'btn-disabled' : ''}`}
|
||||
href={{ pathname: '/beers', query: { page_num: pageNum + 1 } }}
|
||||
scroll={false}
|
||||
prefetch={true}
|
||||
>
|
||||
»
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default BeerIndexPaginationBar;
|
||||
@@ -1,37 +0,0 @@
|
||||
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;
|
||||
@@ -22,7 +22,7 @@ const FormPageLayout: FC<FormPageLayoutProps> = ({
|
||||
<div className="align-center my-20 flex h-fit flex-col items-center justify-center">
|
||||
<div className="w-8/12">
|
||||
<div className="tooltip tooltip-bottom absolute" data-tip={backLinkText}>
|
||||
<Link href={backLink} className="btn btn-ghost btn-sm">
|
||||
<Link href={backLink} className="btn-ghost btn-sm btn p-0">
|
||||
<BiArrowBack className="text-xl" />
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user