From 6c21e4feec7c4e347d992f133a16a185211a2734 Mon Sep 17 00:00:00 2001 From: Robbie Antenesse Date: Fri, 9 Mar 2018 11:39:16 -0700 Subject: [PATCH] Improve pagination for search results --- src/components/MainDisplay.jsx | 13 +++++++++- .../{Pagination.jsx => Pagination/index.jsx} | 15 ++++++----- .../structure/Pagination/styles.scss | 3 +++ src/index.jsx | 26 ++++++++++--------- 4 files changed, 37 insertions(+), 20 deletions(-) rename src/components/structure/{Pagination.jsx => Pagination/index.jsx} (78%) create mode 100644 src/components/structure/Pagination/styles.scss diff --git a/src/components/MainDisplay.jsx b/src/components/MainDisplay.jsx index 51cae62..31c7ecc 100644 --- a/src/components/MainDisplay.jsx +++ b/src/components/MainDisplay.jsx @@ -18,6 +18,7 @@ export class MainDisplay extends Component { dictionaryInfo: PropTypes.object.isRequired, wordsToDisplay: PropTypes.array.isRequired, wordsAreFiltered: PropTypes.bool, + wordsInCurrentList: PropTypes.number, currentPage: PropTypes.number, itemsPerPage: PropTypes.number, stats: PropTypes.object.isRequired, @@ -57,6 +58,7 @@ export class MainDisplay extends Component { dictionaryInfo, wordsToDisplay, wordsAreFiltered, + wordsInCurrentList, currentPage, itemsPerPage, stats, @@ -105,6 +107,14 @@ export class MainDisplay extends Component { )} + + + setPage={setPage} + wordsInCurrentList={wordsInCurrentList} /> diff --git a/src/components/structure/Pagination.jsx b/src/components/structure/Pagination/index.jsx similarity index 78% rename from src/components/structure/Pagination.jsx rename to src/components/structure/Pagination/index.jsx index e57fa12..83d4f64 100644 --- a/src/components/structure/Pagination.jsx +++ b/src/components/structure/Pagination/index.jsx @@ -1,24 +1,25 @@ import Inferno from 'inferno'; import PropTypes from 'prop-types'; +import './styles.scss'; + export const Pagination = (props) => { PropTypes.checkPropTypes({ currentPage: PropTypes.number.isRequired, itemsPerPage: PropTypes.number.isRequired, stats: PropTypes.object.isRequired, setPage: PropTypes.func.isRequired, + wordsInCurrentList: PropTypes.number, + isTop: PropTypes.bool, }, props, 'prop', 'Pagination'); - const { currentPage, itemsPerPage, stats, setPage } = props; - - const totalWords = stats.hasOwnProperty('numberOfWords') - ? stats.numberOfWords.find(group => group.name === 'Total').value : null; + const { currentPage, itemsPerPage, stats, setPage, wordsInCurrentList, isTop } = props; - if (totalWords === null) { + if (wordsInCurrentList === null) { return
; } - const lastPage = Math.floor(totalWords / itemsPerPage); + const lastPage = Math.floor(wordsInCurrentList / itemsPerPage); const nextPage = currentPage + 1 > lastPage ? lastPage : currentPage + 1; const prevPage = currentPage - 1 < 0 ? 0 : currentPage - 1; @@ -29,7 +30,7 @@ export const Pagination = (props) => { } return ( -