import Inferno from 'inferno'; import PropTypes from 'prop-types'; export const Pagination = (props) => { PropTypes.checkPropTypes({ currentPage: PropTypes.number.isRequired, itemsPerPage: PropTypes.number.isRequired, stats: PropTypes.object.isRequired, setPage: PropTypes.func.isRequired, }, props, 'prop', 'Pagination'); const { currentPage, itemsPerPage, stats, setPage } = props; const totalWords = stats.hasOwnProperty('numberOfWords') ? stats.numberOfWords.find(group => group.name === 'Total').value : null; if (totalWords === null) { return
; } const lastPage = Math.floor(totalWords / itemsPerPage); const nextPage = currentPage + 1 > lastPage ? lastPage : currentPage + 1; const prevPage = currentPage - 1 < 0 ? 0 : currentPage - 1; const changePage = (page) => { if (page !== currentPage && page <= lastPage && page >= 0) { setPage(page); } } return ( ); }