mirror of
https://github.com/ascribe/onion.git
synced 2024-11-15 01:25:17 +01:00
Make Pagination more generic
This commit is contained in:
parent
2c3b7c3025
commit
d77cc20da6
@ -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">←</span>
|
||||
Previous
|
||||
</Link>
|
||||
</li>
|
||||
<li className="next">
|
||||
<Link to="pieces"
|
||||
query={{page: next}}
|
||||
onClick={this.goToPage(next)}>
|
||||
Next
|
||||
<span aria-hidden="true">→</span>
|
||||
</Link>
|
||||
</li>
|
||||
<PaginationButton
|
||||
direction='previous'
|
||||
goToPage={this.props.goToPage}>
|
||||
</PaginationButton>
|
||||
<PaginationButton
|
||||
direction='next'
|
||||
goToPage={this.props.goToPage}>
|
||||
</PaginationButton>
|
||||
</ul>
|
||||
</nav>
|
||||
);
|
||||
|
44
js/components/pagination_button.js
Normal file
44
js/components/pagination_button.js
Normal 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">←</span> Previous
|
||||
</span>
|
||||
);
|
||||
} else {
|
||||
page += 1;
|
||||
directionDisplay = (
|
||||
<span>
|
||||
Next <span aria-hidden="true">→</span>
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<li className={this.props.direction}>
|
||||
<Link to="pieces"
|
||||
query={{page}}
|
||||
onClick={this.props.goToPage(page)}>
|
||||
{directionDisplay}
|
||||
</Link>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
export default PaginationButton;
|
@ -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>
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user