From c59f5267ce7455f7b0c89050610a8b1f54c509b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20Daubensch=C3=BCtz?= Date: Mon, 12 Oct 2015 16:38:00 +0200 Subject: [PATCH] add threshold functionality to SearchBar --- js/actions/piece_list_actions.js | 2 +- .../piece_list_toolbar.js | 6 ++- js/components/piece_list.js | 1 + js/components/search_bar.js | 42 +++++++++++++++---- 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/js/actions/piece_list_actions.js b/js/actions/piece_list_actions.js index 87304ca7..f4231a0b 100644 --- a/js/actions/piece_list_actions.js +++ b/js/actions/piece_list_actions.js @@ -22,10 +22,10 @@ class PieceListActions { this.actions.updatePieceList({ page, pageSize, - search, orderBy, orderAsc, filterBy, + search: '', pieceList: [], pieceListCount: -1, unfilteredPieceListCount: -1 diff --git a/js/components/ascribe_piece_list_toolbar/piece_list_toolbar.js b/js/components/ascribe_piece_list_toolbar/piece_list_toolbar.js index d2c3265f..8f65fb31 100644 --- a/js/components/ascribe_piece_list_toolbar/piece_list_toolbar.js +++ b/js/components/ascribe_piece_list_toolbar/piece_list_toolbar.js @@ -11,6 +11,7 @@ let PieceListToolbar = React.createClass({ propTypes: { className: React.PropTypes.string, searchFor: React.PropTypes.func, + searchQuery: React.PropTypes.string, filterParams: React.PropTypes.arrayOf( React.PropTypes.shape({ label: React.PropTypes.string, @@ -61,7 +62,7 @@ let PieceListToolbar = React.createClass({ }, render() { - const { className, children, searchFor } = this.props; + const { className, children, searchFor, searchQuery } = this.props; return (
@@ -74,7 +75,8 @@ let PieceListToolbar = React.createClass({ + searchQuery={searchQuery} + threshold={500}/> {this.getOrderWidget()} {this.getFilterWidget()} diff --git a/js/components/piece_list.js b/js/components/piece_list.js index 35dcaba0..908c2821 100644 --- a/js/components/piece_list.js +++ b/js/components/piece_list.js @@ -157,6 +157,7 @@ let PieceList = React.createClass({ { + const { timers } = this.state; + + if(timers.length <= timerIndex + 1) { + // clean the timers array + this.setState({ timers: [], searching: true }, () => { + // search for the query + this.props.searchFor(searchQuery); + }); + } + }; }, handleChange({ target: { value }}) { this.startTimers(value); - this.setState({ currentSearchQuery: value }); + this.setState({ searchQuery: value }); }, render() { - const searchIcon = ; + let searchIcon = ; const { className } = this.props; + const { searching } = this.state; + + if(searching) { + searchIcon = ; + } return (