Moved helper functions to render progressive paginators to a common place

This commit is contained in:
Alejandro Celaya
2020-03-28 17:25:12 +01:00
parent 06db4f6556
commit 2d5c2779c3
4 changed files with 28 additions and 27 deletions

View File

@@ -1,7 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { Pagination, PaginationItem, PaginationLink } from 'reactstrap';
import { range, max, min } from 'ramda';
import { ELLIPSIS, progressivePagination } from '../utils/utils';
import './SimplePaginator.scss';
const propTypes = {
@@ -10,28 +10,6 @@ const propTypes = {
setCurrentPage: PropTypes.func.isRequired,
};
export const ELLIPSIS = '...';
export const progressivePagination = (currentPage, pageCount) => {
const delta = 2;
const pages = range(
max(delta, currentPage - delta),
min(pageCount - 1, currentPage + delta) + 1
);
if (currentPage - delta > delta) {
pages.unshift(ELLIPSIS);
}
if (currentPage + delta < pageCount - 1) {
pages.push(ELLIPSIS);
}
pages.unshift(1);
pages.push(pageCount);
return pages;
};
const SimplePaginator = ({ pagesCount, currentPage, setCurrentPage }) => {
if (pagesCount < 2) {
return null;