import { FunctionComponent, useMemo } from "react"; import { Col, Container, Pagination, Row } from "react-bootstrap"; import { PageControlAction } from "./types"; interface Props { count: number; index: number; size: number; total: number; canPrevious: boolean; previous: () => void; canNext: boolean; next: () => void; goto: (idx: number) => void; loadState?: PageControlAction; } const PageControl: FunctionComponent = ({ count, index, size, total, canPrevious, previous, canNext, next, goto, loadState, }) => { const empty = total === 0; const start = empty ? 0 : size * index + 1; const end = Math.min(size * (index + 1), total); const loading = loadState !== undefined; const pageButtons = useMemo( () => [...Array(count).keys()] .map((idx) => { if (Math.abs(idx - index) >= 4 && idx !== 0 && idx !== count - 1) { return null; } else { return ( goto(idx)} > {idx + 1} ); } }) .flatMap((item, idx, arr) => { if (item === null) { if (arr[idx + 1] === null) { return []; } else { return ( ); } } else { return [item]; } }), [count, index, goto, loading] ); return ( Show {start} to {end} of {total} entries ); }; export default PageControl;