From 8bdc8d41d4b19458f7dc5ca9ba8f03a3b718ef0f Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Wed, 24 Oct 2018 13:53:11 -0400 Subject: [PATCH] start pagination at the end --- embark-ui/src/components/Pagination.js | 11 +++++++---- embark-ui/src/containers/BlocksContainer.js | 5 +++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/embark-ui/src/components/Pagination.js b/embark-ui/src/components/Pagination.js index ca8e003c..2d566115 100644 --- a/embark-ui/src/components/Pagination.js +++ b/embark-ui/src/components/Pagination.js @@ -5,13 +5,16 @@ import PropTypes from 'prop-types'; const NB_PAGES_MAX = 8; const Pages = ({currentPage, numberOfPages, changePage}) => { - let i = currentPage - NB_PAGES_MAX / 2; + let max = currentPage + NB_PAGES_MAX / 2; + if (max >= numberOfPages) { + max = numberOfPages; + } + let i = max - NB_PAGES_MAX; if (i < 1) { i = 1; } - let max = i + NB_PAGES_MAX - 1; - if (max > numberOfPages) { - max = numberOfPages; + if (max - i < NB_PAGES_MAX) { + max += NB_PAGES_MAX - max + 1; } const pageNumbers = []; for (i; i <= max; i++) { diff --git a/embark-ui/src/containers/BlocksContainer.js b/embark-ui/src/containers/BlocksContainer.js index 3e2dbe4b..c580d70b 100644 --- a/embark-ui/src/containers/BlocksContainer.js +++ b/embark-ui/src/containers/BlocksContainer.js @@ -13,7 +13,7 @@ class BlocksContainer extends Component { constructor(props) { super(props); - this.state = {currentPage: 1}; + this.state = {currentPage: 0}; } componentDidMount() { @@ -50,7 +50,8 @@ class BlocksContainer extends Component { 0} {...this.props} render={({blocks}) => ( this.changePage(newPage)} currentPage={this.state.currentPage} /> + changePage={(newPage) => this.changePage(newPage)} + currentPage={this.state.currentPage || this.getNumberOfPages()} /> )} /> );