diff --git a/embark-ui/src/components/Blocks.js b/embark-ui/src/components/Blocks.js
index 405fa0fc..1f311de8 100644
--- a/embark-ui/src/components/Blocks.js
+++ b/embark-ui/src/components/Blocks.js
@@ -6,7 +6,7 @@ import Pages from './Pagination';
import CardTitleIdenticon from './CardTitleIdenticon';
-const Blocks = ({blocks, changePage, currentPage}) => (
+const Blocks = ({blocks, changePage, currentPage, numberOfPages}) => (
@@ -37,7 +37,7 @@ const Blocks = ({blocks, changePage, currentPage}) => (
))}
-
+
@@ -47,7 +47,8 @@ const Blocks = ({blocks, changePage, currentPage}) => (
Blocks.propTypes = {
blocks: PropTypes.arrayOf(PropTypes.object),
changePage: PropTypes.func,
- currentPage: PropTypes.number
+ currentPage: PropTypes.number,
+ numberOfPages: PropTypes.number
};
export default Blocks;
diff --git a/embark-ui/src/components/Pagination.js b/embark-ui/src/components/Pagination.js
index bc3ed83f..4a62c377 100644
--- a/embark-ui/src/components/Pagination.js
+++ b/embark-ui/src/components/Pagination.js
@@ -2,27 +2,43 @@ import React from 'react';
import {Pagination, PaginationItem, PaginationLink} from 'reactstrap';
import PropTypes from 'prop-types';
+const NB_PAGES_MAX = 14;
+
const Pages = ({currentPage, numberOfPages, changePage}) => {
- const paginationItems = [];
- for (let i = 1; i <= numberOfPages; i++) {
- paginationItems.push(
- {
- e.preventDefault();
- changePage(i);
- }}>
- {i}
-
- );
+ let i = currentPage - NB_PAGES_MAX / 2;
+ if (i < 1) {
+ i = 1;
+ }
+ let max = i + NB_PAGES_MAX;
+ if (max > numberOfPages) {
+ max = numberOfPages;
+ }
+ const pageNumbers = [];
+ for (i; i <= max; i++) {
+ pageNumbers.push(i);
}
return (
-
-
+
+ {
+ e.preventDefault();
+ changePage(currentPage - 1);
+ }}/>
- {paginationItems}
-
-
+ {pageNumbers.map(number => (
+ {
+ e.preventDefault();
+ changePage(number);
+ }}>
+ {number}
+
+ ))}
+ = numberOfPages}>
+ {
+ e.preventDefault();
+ changePage(currentPage + 1);
+ }}/>
);
diff --git a/embark-ui/src/containers/BlocksContainer.js b/embark-ui/src/containers/BlocksContainer.js
index c5038dab..3e2dbe4b 100644
--- a/embark-ui/src/containers/BlocksContainer.js
+++ b/embark-ui/src/containers/BlocksContainer.js
@@ -7,6 +7,8 @@ import Blocks from '../components/Blocks';
import DataWrapper from "../components/DataWrapper";
import {getBlocks} from "../reducers/selectors";
+const MAX_BLOCKS = 10; // TODO use same constant as API
+
class BlocksContainer extends Component {
constructor(props) {
super(props);
@@ -27,6 +29,10 @@ class BlocksContainer extends Component {
this.props.fetchBlocks(this.loadMoreFrom());
}
+ getNumberOfPages() {
+ return Math.ceil(this.loadMoreFrom() / MAX_BLOCKS);
+ }
+
loadMoreFrom() {
let blocks = this.props.blocks;
if (blocks.length === 0) {
@@ -43,7 +49,7 @@ class BlocksContainer extends Component {
return (
0} {...this.props} render={({blocks}) => (
- = 0)}
+ this.changePage(newPage)} currentPage={this.state.currentPage} />
)} />