Skip to content
Snippets Groups Projects
Commit a7fdc254 authored by Dima Rifai's avatar Dima Rifai
Browse files

Issue #372 - Fix pagination logic

parent b73dff19
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,7 @@ interface CustomPaginationProps {
isMirrored?: boolean;
className?: string;
handleLatestPage?: () => void;
handleFirstPage?:()=>void;
}
const CustomPagination: React.FC<CustomPaginationProps> = ({
......@@ -29,9 +30,10 @@ const CustomPagination: React.FC<CustomPaginationProps> = ({
siblingCount = 1,
pageSize,
onPageChange,
isMirrored = true,
isMirrored = false,
className,
handleLatestPage,
handleFirstPage
}) => {
const paginationRange = usePagination({
currentPage,
......@@ -54,14 +56,27 @@ const CustomPagination: React.FC<CustomPaginationProps> = ({
};
const onFirstPage = () => {
onPageChange(1);
};
if (handleFirstPage) {
handleFirstPage(); // Use the custom handler if provided
} else {
onPageChange(1); // Default behavior: go to the last page
}
}
const maxPage = Math.max(
Number(paginationRange[0]),
Number(paginationRange.at(-1))
);
const lastPage = Math.ceil(totalCount / pageSize);
const onLastPage = () => {
if (handleLatestPage) {
handleLatestPage(); // Use the custom handler if provided
} else {
onPageChange(lastPage); // Default behavior: go to the last page
}
}
return (
<Pagination className={className}>
<PaginationContent className="md:gap-x-4">
......@@ -69,7 +84,7 @@ const CustomPagination: React.FC<CustomPaginationProps> = ({
(isMirrored ? currentPage !== maxPage : currentPage !== 1) && (
<>
<PaginationItem
onClick={handleLatestPage}
onClick={isMirrored ? onLastPage : onFirstPage}
className="cursor-pointer"
>
<PaginationLatest />
......@@ -128,7 +143,7 @@ const CustomPagination: React.FC<CustomPaginationProps> = ({
<PaginationNext />
</PaginationItem>
<PaginationItem
onClick={onFirstPage}
onClick={isMirrored ? onFirstPage : onLastPage}
className="cursor-pointer"
>
<PaginationFirst />
......@@ -140,4 +155,4 @@ const CustomPagination: React.FC<CustomPaginationProps> = ({
);
};
export default CustomPagination;
export default CustomPagination;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment