import { Link } from 'react-router-dom'; import { Pagination, PaginationItem, PaginationLink } from 'reactstrap'; import type { ShlinkPaginator } from '../api-contract'; import type { NumberOrEllipsis } from '../utils/helpers/pagination'; import { keyForPage, pageIsEllipsis, prettifyPageNumber, progressivePagination, } from '../utils/helpers/pagination'; import { useRoutesPrefix } from '../utils/routesPrefix'; interface PaginatorProps { paginator?: ShlinkPaginator; currentQueryString?: string; } export const Paginator = ({ paginator, currentQueryString = '' }: PaginatorProps) => { const { currentPage = 0, pagesCount = 0 } = paginator ?? {}; const routesPrefix = useRoutesPrefix(); const urlForPage = (pageNumber: NumberOrEllipsis) => `${routesPrefix}/list-short-urls/${pageNumber}${currentQueryString}`; if (pagesCount <= 1) { return
; // Return some space } const renderPages = () => progressivePagination(currentPage, pagesCount).map((pageNumber, index) => ( {prettifyPageNumber(pageNumber)} )); return ( {renderPages()} = pagesCount}> ); };