diff --git a/src/components/Paginate.jsx b/src/components/Paginate.jsx index da8d3be..cc292d0 100644 --- a/src/components/Paginate.jsx +++ b/src/components/Paginate.jsx @@ -27,6 +27,8 @@ export const Paginate = (props) => { const pageNeighbours = typeof props.pageNeighbours === 'number' ? Math.max(0, Math.min(props.pageNeighbours, 2)) : 0; const totalPages = Math.ceil(totalRecords / pageLimit); const [currentPage, setCurrentPage] = useState(typeof props.currentPage === 'number' ? props.currentPage : 1); + let hasLeft = false; + let hasRight = false; const gotoPage = (page) => { const currentPage = Math.max(0, Math.min(page, totalPages)); @@ -88,14 +90,18 @@ export const Paginate = (props) => { // handle: (1) < {5 6} [7] {8 9} (10) if (hasLeftSpill && !hasRightSpill) { const extraPages = range(startPage - spillOffset, startPage - 1); - pages = [LEFT_PAGE, 1, SPACE_A, ...extraPages, ...pages]; + hasLeft = true; + pages = [1, SPACE_A, ...extraPages, ...pages]; // handle: (1) {2 3} [4] {5 6} > (10) } else if (!hasLeftSpill && hasRightSpill) { const extraPages = range(endPage + 1, endPage + spillOffset); - pages = [1, ...pages, ...extraPages, SPACE_B, totalPages, RIGHT_PAGE]; + hasRight = true; + pages = [1, ...pages, ...extraPages, SPACE_B, totalPages]; // handle: (1) < {4 5} [6] {7 8} > (10) } else if (hasLeftSpill && hasRightSpill) { - pages = [LEFT_PAGE, 1, SPACE_A, ...pages, SPACE_B, totalPages, RIGHT_PAGE]; + hasLeft = true; + hasRight = true; + pages = [1, SPACE_A, ...pages, SPACE_B, totalPages]; } return pages; @@ -110,24 +116,9 @@ export const Paginate = (props) => { const pages = fetchPageNumbers(); const blocks = pages.map((page, index) => { - if (page === LEFT_PAGE) return ( -