diff --git a/public/assets/icons/arrow-left.svg b/public/assets/icons/arrow-left.svg index 52dc05c6..f8ff17a2 100644 --- a/public/assets/icons/arrow-left.svg +++ b/public/assets/icons/arrow-left.svg @@ -1,3 +1,3 @@ diff --git a/public/assets/icons/arrow-right.svg b/public/assets/icons/arrow-right.svg index b25599ae..820e9c21 100644 --- a/public/assets/icons/arrow-right.svg +++ b/public/assets/icons/arrow-right.svg @@ -1,3 +1,3 @@ diff --git a/src/components/common/PaginationControls/index.tsx b/src/components/common/PaginationControls/index.tsx index 3e0ca0bf..da2fe727 100644 --- a/src/components/common/PaginationControls/index.tsx +++ b/src/components/common/PaginationControls/index.tsx @@ -1,6 +1,6 @@ -import LeftArrowIcon from '@/public/assets/icons/page-left-icon.svg'; -import RightArrowIcon from '@/public/assets/icons/page-right-icon.svg'; -import { useEffect, useState } from 'react'; +import Typography from '@/components/common/Typography'; +import LeftArrowIcon from '@/public/assets/icons/arrow-left.svg'; +import RightArrowIcon from '@/public/assets/icons/arrow-right.svg'; import style from './style.module.scss'; interface PaginationControlsProps { @@ -9,12 +9,18 @@ interface PaginationControlsProps { pages: number; } -const PaginationControls = ({ page, onPage, pages }: PaginationControlsProps) => { - const [value, setValue] = useState(String(page + 1)); +function calculatePagesToDisplay(page: number, totalPages: number, maxWidth: number): number[] { + const radius = (maxWidth - 1) / 2; + if (page + radius >= totalPages) { + return Array.from({ length: maxWidth }, (_, key) => totalPages - maxWidth + 1 + key); + } + const displayPage = page + 1; + const start = Math.max(1, displayPage - radius); + return Array.from({ length: Math.min(maxWidth, totalPages) }, (_, key) => start + key); +} - useEffect(() => { - setValue(String(page + 1)); - }, [page]); +const PaginationControls = ({ page, onPage, pages }: PaginationControlsProps) => { + const pagesToDisplay = calculatePagesToDisplay(page, pages, 5); return (