use constructor bound methods for pagination

This commit is contained in:
Jake McDermott 2019-01-03 12:26:46 -05:00
parent 6446e45165
commit 87101a487d
No known key found for this signature in database
GPG Key ID: 9A6F084352C3A0B7

View File

@ -21,6 +21,15 @@ class Pagination extends Component {
const { page } = this.props;
this.state = { value: page, isOpen: false };
this.onPageChange = this.onPageChange.bind(this);
this.onSubmit = this.onSubmit.bind(this);
this.onFirst = this.onFirst.bind(this);
this.onPrevious = this.onPrevious.bind(this);
this.onNext = this.onNext.bind(this);
this.onLast = this.onLast.bind(this);
this.onTogglePageSize = this.onTogglePageSize.bind(this);
this.onSelectPageSize = this.onSelectPageSize.bind(this);
}
componentDidUpdate (prevProps) {
@ -31,11 +40,11 @@ class Pagination extends Component {
}
}
onPageChange = value => {
onPageChange (value) {
this.setState({ value });
};
}
onSubmit = event => {
onSubmit (event) {
const { onSetPage, page, pageCount, page_size } = this.props;
const { value } = this.state;
@ -49,43 +58,43 @@ class Pagination extends Component {
} else {
this.setState({ value: page });
}
};
}
onFirst = () => {
onFirst () {
const { onSetPage, page_size } = this.props;
onSetPage(1, page_size);
};
}
onPrevious = () => {
onPrevious () {
const { onSetPage, page, page_size } = this.props;
const previousPage = page - 1;
if (previousPage >= 1) {
onSetPage(previousPage, page_size);
}
};
}
onNext = () => {
onNext () {
const { onSetPage, page, pageCount, page_size } = this.props;
const nextPage = page + 1;
if (nextPage <= pageCount) {
onSetPage(nextPage, page_size);
}
};
}
onLast = () => {
onLast () {
const { onSetPage, pageCount, page_size } = this.props;
onSetPage(pageCount, page_size)
};
}
onTogglePageSize = isOpen => {
onTogglePageSize (isOpen) {
this.setState({ isOpen });
};
}
onSelectPageSize = ({ target }) => {
onSelectPageSize ({ target }) {
const { onSetPage } = this.props;
const page = 1;
@ -94,7 +103,7 @@ class Pagination extends Component {
this.setState({ isOpen: false });
onSetPage(page, page_size);
};
}
render () {
const { up } = DropdownDirection;