/** * * Pagination * */ import React from 'react'; import styles from './styles.scss'; class Pagination extends React.Component { // eslint-disable-line react/prefer-stateless-function constructor(props) { super(props); this.state = { progress: -1, }; this.onGoPreviousPageClicked = this.onGoPreviousPageClicked.bind(this); this.onGoNextPageClicked = this.onGoNextPageClicked.bind(this); } /** * Check if the current page is the first one or not * * @returns {boolean} */ isFirstPage() { return this.props.currentPage === 1; } /** * Check if the * * @returns {boolean} */ needPreviousLinksDots() { return this.props.currentPage >= 3; } needAfterLinksDots() { return this.props.currentPage < this.lastPage() - 1; } /** * Return the last page number * * @returns {number} */ lastPage() { return Math.ceil(this.props.count / this.props.limitPerPage); } /** * Check if the current page is the last one * * @returns {boolean} */ isLastPage() { return this.props.currentPage === this.lastPage(); } /** * Triggered on previous page click. * * Prevent link default behavior and go to previous page. * * @param e {Object} Click event */ onGoPreviousPageClicked(e) { e.preventDefault(); if (!this.isFirstPage()) { this.props.goPreviousPage(); } } /** * Triggered on next page click. * * Prevent link default behavior and go to next page. * * @param e {Object} Click event */ onGoNextPageClicked(e) { e.preventDefault(); if (!this.isLastPage()) { this.props.goNextPage(); } } render() { // Init variables let beforeLinksDots; let afterLinksDots; const linksOptions = []; const dotsElem = (