1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 09:35:10 +01:00

Fix pagination on search bug

This commit is contained in:
Tim Daubenschütz 2015-06-16 09:27:04 +02:00
parent 7910384d99
commit 1ce9b90fff
3 changed files with 14 additions and 24 deletions

View File

@ -9,7 +9,6 @@ let Pagination = React.createClass({
goToPage: React.PropTypes.func.isRequired, goToPage: React.PropTypes.func.isRequired,
currentPage: React.PropTypes.number.isRequired, currentPage: React.PropTypes.number.isRequired,
totalPages: React.PropTypes.number.isRequired totalPages: React.PropTypes.number.isRequired
//itemListCount: React.PropTypes.number.isRequired
}, },
render() { render() {

View File

@ -2,37 +2,19 @@
import React from 'react'; import React from 'react';
import PieceListStore from '../../stores/piece_list_store';
import PieceListActions from '../../actions/piece_list_actions';
import Input from 'react-bootstrap/lib/Input'; import Input from 'react-bootstrap/lib/Input';
import Glyphicon from 'react-bootstrap/lib/Glyphicon'; import Glyphicon from 'react-bootstrap/lib/Glyphicon';
let PieceListToolbar = React.createClass({ let PieceListToolbar = React.createClass({
propTypes: { propTypes: {
className: React.PropTypes.string className: React.PropTypes.string,
}, searchFor: React.PropTypes.func
getInitialState() {
return PieceListStore.getState();
},
componentDidMount() {
PieceListStore.listen(this.onChange);
},
componentWillUnmount() {
PieceListStore.unlisten(this.onChange);
},
onChange(state) {
this.setState(state);
}, },
searchFor() { searchFor() {
let searchTerm = this.refs.search.getInputDOMNode().value; let searchTerm = this.refs.search.getInputDOMNode().value;
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, searchTerm, this.state.orderBy, this.state.orderAsc); this.props.searchFor(searchTerm);
}, },
render() { render() {

View File

@ -1,6 +1,7 @@
'use strict'; 'use strict';
import React from 'react'; import React from 'react';
import Router from 'react-router';
import PieceListStore from '../stores/piece_list_store'; import PieceListStore from '../stores/piece_list_store';
import PieceListActions from '../actions/piece_list_actions'; import PieceListActions from '../actions/piece_list_actions';
@ -20,6 +21,8 @@ let PieceList = React.createClass({
query: React.PropTypes.object query: React.PropTypes.object
}, },
mixins: [Router.Navigation, Router.State],
getInitialState() { getInitialState() {
return PieceListStore.getState(); return PieceListStore.getState();
}, },
@ -30,7 +33,6 @@ let PieceList = React.createClass({
if (this.state.pieceList.length === 0){ if (this.state.pieceList.length === 0){
PieceListActions.fetchPieceList(page, this.state.pageSize, this.state.search, this.state.orderBy, this.state.orderAsc); PieceListActions.fetchPieceList(page, this.state.pageSize, this.state.search, this.state.orderBy, this.state.orderAsc);
} }
}, },
componentWillUnmount() { componentWillUnmount() {
@ -47,6 +49,11 @@ let PieceList = React.createClass({
this.state.orderAsc); this.state.orderAsc);
}, },
searchFor(searchTerm) {
PieceListActions.fetchPieceList(1, this.state.pageSize, searchTerm, this.state.orderBy, this.state.orderAsc);
this.transitionTo(this.getPathname(), {page: 1});
},
accordionChangeOrder(orderBy, orderAsc) { accordionChangeOrder(orderBy, orderAsc) {
PieceListActions.fetchPieceList(this.state.page, this.state.pageSize, PieceListActions.fetchPieceList(this.state.page, this.state.pageSize,
this.state.search, orderBy, orderAsc); this.state.search, orderBy, orderAsc);
@ -58,7 +65,9 @@ let PieceList = React.createClass({
return ( return (
<div> <div>
<PieceListToolbar className="ascribe-piece-list-toolbar" /> <PieceListToolbar
className="ascribe-piece-list-toolbar"
searchFor={this.searchFor} />
<PieceListBulkModal className="ascribe-piece-list-bulk-modal" /> <PieceListBulkModal className="ascribe-piece-list-bulk-modal" />
<AccordionList <AccordionList
className="ascribe-accordion-list" className="ascribe-accordion-list"