1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 09:23:13 +01:00

Make Pagination more generic

This commit is contained in:
Tim Daubenschütz 2015-05-22 12:58:06 +02:00
parent 2c3b7c3025
commit d77cc20da6
3 changed files with 61 additions and 24 deletions

View File

@ -1,14 +1,10 @@
import React from 'react';
import Router from 'react-router';
let Link = Router.Link;
import PaginationButton from './pagination_button';
let Pagination = React.createClass({
goToPage(page) {
return () => this.props.fetchList(page, this.props.pageSize, this.props.search,
this.props.orderBy, this.props.orderAsc);
propTypes: {
goToPage: React.PropTypes.func.isRequired
},
render() {
@ -18,22 +14,14 @@ let Pagination = React.createClass({
return(
<nav>
<ul className="pager">
<li className="previous">
<Link to="pieces"
query={{page: prev}}
onClick={this.goToPage(prev)}>
<span aria-hidden="true">&larr;</span>
Previous
</Link>
</li>
<li className="next">
<Link to="pieces"
query={{page: next}}
onClick={this.goToPage(next)}>
Next
<span aria-hidden="true">&rarr;</span>
</Link>
</li>
<PaginationButton
direction='previous'
goToPage={this.props.goToPage}>
</PaginationButton>
<PaginationButton
direction='next'
goToPage={this.props.goToPage}>
</PaginationButton>
</ul>
</nav>
);

View File

@ -0,0 +1,44 @@
import React from 'react';
import Router from 'react-router';
let Link = Router.Link;
let PaginationButton = React.createClass({
propTypes: {
direction: React.PropTypes.oneOf(['previous', 'next']),
goToPage: React.PropTypes.func.isRequired
},
render() {
let page = parseInt(this.props.page, 10);
let directionDisplay;
if(this.props.direction === 'previous') {
page -= 1;
directionDisplay = (
<span>
<span aria-hidden="true">&larr;</span> Previous
</span>
);
} else {
page += 1;
directionDisplay = (
<span>
Next <span aria-hidden="true">&rarr;</span>
</span>
);
}
return (
<li className={this.props.direction}>
<Link to="pieces"
query={{page}}
onClick={this.props.goToPage(page)}>
{directionDisplay}
</Link>
</li>
);
}
});
export default PaginationButton;

View File

@ -26,6 +26,11 @@ let PieceList = React.createClass({
this.state.orderBy, this.state.orderAsc);
},
paginationGoToPage(page) {
return () => PieceListActions.fetchPieceList(page, this.state.pageSize, this.state.search,
this.state.orderBy, this.state.orderAsc);
},
render() {
let columnList = [
new TableColumnModel('thumbnail', '', TableItemImg, 2, false),
@ -49,7 +54,7 @@ let PieceList = React.createClass({
}
}}>
<Table columnList={columnList} />
<Pagination currentPage={this.props.query.page} />
<Pagination currentPage={this.props.query.page} goToPage={this.paginationGoToPage} />
</AltContainer>
);
}