From e177263d9f97fbf334073e1fd934092cbe149859 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Mon, 4 Jan 2016 16:54:27 +0000 Subject: [PATCH] Address review comments Minor fixes post-review --- src/components/structures/RoomView.js | 21 +++++++++++---------- src/components/views/rooms/RoomHeader.js | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/components/structures/RoomView.js b/src/components/structures/RoomView.js index 96bd71bd23..334fc02e18 100644 --- a/src/components/structures/RoomView.js +++ b/src/components/structures/RoomView.js @@ -511,12 +511,11 @@ module.exports = React.createClass({ if (DEBUG_SCROLL) console.log("sending search request"); - var searchPromise = MatrixClientPeg.get().searchRoomEvents( - { filter: filter, - term: term, - }); - this._handleSearchResult(searchPromise) - .done(); + var searchPromise = MatrixClientPeg.get().searchRoomEvents({ + filter: filter, + term: term, + }); + this._handleSearchResult(searchPromise).done(); }, _backPaginateSearch: function() { @@ -524,13 +523,15 @@ module.exports = React.createClass({ var searchPromise = MatrixClientPeg.get().backPaginateRoomEventsSearch( this.state.searchResults); - this._handleSearchResult(searchPromise) - .done(); + this._handleSearchResult(searchPromise).done(); }, _handleSearchResult: function(searchPromise) { var self = this; - var searchId = this.searchId; + + // keep a record of the current search id, so that if the search terms + // change before we get a response, we can ignore the results. + var localSearchId = this.searchId; this.setState({ searchInProgress: true, @@ -538,7 +539,7 @@ module.exports = React.createClass({ return searchPromise.then(function(results) { if (DEBUG_SCROLL) console.log("search complete"); - if (!self.state.searching || self.searchId != searchId) { + if (!self.state.searching || self.searchId != localSearchId) { console.error("Discarding stale search results"); return; } diff --git a/src/components/views/rooms/RoomHeader.js b/src/components/views/rooms/RoomHeader.js index 0183ce2116..f1cfb67fe3 100644 --- a/src/components/views/rooms/RoomHeader.js +++ b/src/components/views/rooms/RoomHeader.js @@ -109,7 +109,7 @@ module.exports = React.createClass({ var searchStatus; // don't display the search count until the search completes and - // gives us a non-null searchCount. + // gives us a valid (possibly zero) searchCount. if (this.props.searchInfo && this.props.searchInfo.searchCount != null) { searchStatus =
 (~{ this.props.searchInfo.searchCount } results)
; }