2015-05-22 12:58:06 +02:00
|
|
|
import React from 'react';
|
|
|
|
import Router from 'react-router';
|
|
|
|
|
2015-06-02 14:25:26 +02:00
|
|
|
import { getLangText } from '../../utils/lang_utils';
|
|
|
|
|
2015-05-22 12:58:06 +02:00
|
|
|
let Link = Router.Link;
|
|
|
|
|
|
|
|
let PaginationButton = React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
direction: React.PropTypes.oneOf(['previous', 'next']),
|
2015-05-22 13:43:53 +02:00
|
|
|
goToPage: React.PropTypes.func.isRequired,
|
2015-05-22 17:11:17 +02:00
|
|
|
currentPage: React.PropTypes.number.isRequired,
|
|
|
|
totalPages: React.PropTypes.number.isRequired
|
|
|
|
},
|
|
|
|
|
|
|
|
isInRange(page) {
|
|
|
|
return page > 0 && page <= this.props.totalPages;
|
2015-05-22 12:58:06 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let directionDisplay;
|
2015-05-22 17:11:17 +02:00
|
|
|
let page = this.props.currentPage;
|
2015-05-22 13:43:53 +02:00
|
|
|
let isDisabled = '';
|
2015-05-22 17:11:17 +02:00
|
|
|
let anchor;
|
2015-05-22 13:43:53 +02:00
|
|
|
|
2015-05-22 12:58:06 +02:00
|
|
|
if(this.props.direction === 'previous') {
|
|
|
|
page -= 1;
|
|
|
|
directionDisplay = (
|
|
|
|
<span>
|
2015-06-02 14:25:26 +02:00
|
|
|
<span aria-hidden="true">←</span> {getLangText('Previous')}
|
2015-05-22 12:58:06 +02:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
page += 1;
|
|
|
|
directionDisplay = (
|
|
|
|
<span>
|
2015-06-02 14:25:26 +02:00
|
|
|
{getLangText('Next')} <span aria-hidden="true">→</span>
|
2015-05-22 12:58:06 +02:00
|
|
|
</span>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-05-22 17:11:17 +02:00
|
|
|
if (this.isInRange(page)) {
|
|
|
|
anchor = (
|
2015-05-22 12:58:06 +02:00
|
|
|
<Link to="pieces"
|
|
|
|
query={{page}}
|
|
|
|
onClick={this.props.goToPage(page)}>
|
|
|
|
{directionDisplay}
|
|
|
|
</Link>
|
2015-05-22 17:11:17 +02:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
isDisabled += ' disabled';
|
|
|
|
anchor = (
|
|
|
|
<a>
|
|
|
|
{directionDisplay}
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<li className={this.props.direction + isDisabled }>
|
|
|
|
{anchor}
|
2015-05-22 12:58:06 +02:00
|
|
|
</li>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-05-22 17:11:17 +02:00
|
|
|
export default PaginationButton;
|