1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 01:39:36 +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 React from 'react';
import Router from 'react-router';
let Link = Router.Link;
import PaginationButton from './pagination_button';
let Pagination = React.createClass({ let Pagination = React.createClass({
propTypes: {
goToPage(page) { goToPage: React.PropTypes.func.isRequired
return () => this.props.fetchList(page, this.props.pageSize, this.props.search,
this.props.orderBy, this.props.orderAsc);
}, },
render() { render() {
@ -18,22 +14,14 @@ let Pagination = React.createClass({
return( return(
<nav> <nav>
<ul className="pager"> <ul className="pager">
<li className="previous"> <PaginationButton
<Link to="pieces" direction='previous'
query={{page: prev}} goToPage={this.props.goToPage}>
onClick={this.goToPage(prev)}> </PaginationButton>
<span aria-hidden="true">&larr;</span> <PaginationButton
Previous direction='next'
</Link> goToPage={this.props.goToPage}>
</li> </PaginationButton>
<li className="next">
<Link to="pieces"
query={{page: next}}
onClick={this.goToPage(next)}>
Next
<span aria-hidden="true">&rarr;</span>
</Link>
</li>
</ul> </ul>
</nav> </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); 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() { render() {
let columnList = [ let columnList = [
new TableColumnModel('thumbnail', '', TableItemImg, 2, false), new TableColumnModel('thumbnail', '', TableItemImg, 2, false),
@ -49,7 +54,7 @@ let PieceList = React.createClass({
} }
}}> }}>
<Table columnList={columnList} /> <Table columnList={columnList} />
<Pagination currentPage={this.props.query.page} /> <Pagination currentPage={this.props.query.page} goToPage={this.paginationGoToPage} />
</AltContainer> </AltContainer>
); );
} }