mirror of https://github.com/embarklabs/embark.git
start pagination at the end
This commit is contained in:
parent
a1b18b74f8
commit
8bdc8d41d4
|
@ -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++) {
|
||||
|
|
|
@ -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 {
|
|||
<React.Fragment>
|
||||
<DataWrapper shouldRender={this.props.blocks.length > 0} {...this.props} render={({blocks}) => (
|
||||
<Blocks blocks={blocks} numberOfPages={this.getNumberOfPages()}
|
||||
changePage={(newPage) => this.changePage(newPage)} currentPage={this.state.currentPage} />
|
||||
changePage={(newPage) => this.changePage(newPage)}
|
||||
currentPage={this.state.currentPage || this.getNumberOfPages()} />
|
||||
)} />
|
||||
</React.Fragment>
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue