From 76ba3f46a9d87b2ec1e40f29c7e57d69d62f3dd7 Mon Sep 17 00:00:00 2001 From: iqbalpa Date: Wed, 10 Jul 2024 19:40:45 +0700 Subject: [PATCH] refactor: create pagination component --- src/components/myPagination/myPagination.tsx | 72 ++++++++++++++++++++ src/modules/home/home.tsx | 60 ++-------------- 2 files changed, 79 insertions(+), 53 deletions(-) create mode 100644 src/components/myPagination/myPagination.tsx diff --git a/src/components/myPagination/myPagination.tsx b/src/components/myPagination/myPagination.tsx new file mode 100644 index 0000000..60b8741 --- /dev/null +++ b/src/components/myPagination/myPagination.tsx @@ -0,0 +1,72 @@ +import React from 'react'; +import { + Pagination, + PaginationContent, + PaginationEllipsis, + PaginationItem, + PaginationLink, + PaginationNext, + PaginationPrevious, + PaginationNextDouble, + PaginationPreviousDouble, +} from '@/components/ui/pagination'; + +interface IMyPagination { + currentPage: number; + setCurrentPage: (page: number) => void; + handleClickPrev: () => void; + handleClickNext: () => void; +} + +const MyPagination: React.FC = ({ + currentPage, + setCurrentPage, + handleClickNext, + handleClickPrev, +}) => { + return ( + + + + setCurrentPage(1)} + className="hover:cursor-pointer" + /> + + + + + {currentPage > 1 && ( + + + + )} + + {currentPage} + + {currentPage < 500 && ( + + + + )} + + + + + setCurrentPage(500)} + className="hover:cursor-pointer" + /> + + + + ); +}; + +export default MyPagination; diff --git a/src/modules/home/home.tsx b/src/modules/home/home.tsx index 1cac40e..802bd1a 100644 --- a/src/modules/home/home.tsx +++ b/src/modules/home/home.tsx @@ -6,17 +6,7 @@ import { Movie } from '@/constant/movie'; import Header from '@/components/header/header'; import Backdrop from '@/components/backdrop/backdrop'; import ListMovies from '@/components/listMovies/listMovies'; -import { - Pagination, - PaginationContent, - PaginationEllipsis, - PaginationItem, - PaginationLink, - PaginationNext, - PaginationPrevious, - PaginationNextDouble, - PaginationPreviousDouble, -} from '@/components/ui/pagination'; +import MyPagination from '@/components/myPagination/myPagination'; const HomeModule: React.FC = () => { const [movies, setMovies] = useState([]); @@ -63,48 +53,12 @@ const HomeModule: React.FC = () => {
- - - - - setCurrentPage(1)} - className="hover:cursor-pointer" - /> - - - - - {currentPage > 1 && ( - - - - )} - - {currentPage} - - {currentPage < maxPage && ( - - - - )} - - - - - setCurrentPage(maxPage)} - className="hover:cursor-pointer" - /> - - - + ); };