summaryrefslogtreecommitdiffstats
path: root/web/react/components/search_results.jsx
diff options
context:
space:
mode:
authorhmhealey <harrisonmhealey@gmail.com>2016-02-08 13:36:13 -0500
committerhmhealey <harrisonmhealey@gmail.com>2016-02-08 15:47:18 -0500
commitbe716c3b668c4b5de385befc0e6ed5ca2116beb6 (patch)
tree710ac35e330cfbbd510f730c586aa71d7fd8de2d /web/react/components/search_results.jsx
parentfa069e4e1f4fc730fd29ab9699240480d84c84d3 (diff)
downloadchat-be716c3b668c4b5de385befc0e6ed5ca2116beb6.tar.gz
chat-be716c3b668c4b5de385befc0e6ed5ca2116beb6.tar.bz2
chat-be716c3b668c4b5de385befc0e6ed5ca2116beb6.zip
Changed SearchResults to update when the channel store receives data
Diffstat (limited to 'web/react/components/search_results.jsx')
-rw-r--r--web/react/components/search_results.jsx30
1 files changed, 25 insertions, 5 deletions
diff --git a/web/react/components/search_results.jsx b/web/react/components/search_results.jsx
index 9dcc99061..4adc3afe0 100644
--- a/web/react/components/search_results.jsx
+++ b/web/react/components/search_results.jsx
@@ -1,6 +1,7 @@
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
+import ChannelStore from '../stores/channel_store.jsx';
import SearchStore from '../stores/search_store.jsx';
import UserStore from '../stores/user_store.jsx';
import SearchBox from './search_bar.jsx';
@@ -11,7 +12,22 @@ import SearchResultsItem from './search_results_item.jsx';
import {FormattedMessage, FormattedHTMLMessage} from 'mm-intl';
function getStateFromStores() {
- return {results: SearchStore.getSearchResults()};
+ const results = SearchStore.getSearchResults();
+
+ const channels = new Map();
+ const channelIds = results.order.map((postId) => results.posts[postId].channel_id);
+ for (const id of channelIds) {
+ if (channels.has(id)) {
+ continue;
+ }
+
+ channels.set(id, ChannelStore.get(id));
+ }
+
+ return {
+ results,
+ channels
+ };
}
export default class SearchResults extends React.Component {
@@ -33,16 +49,22 @@ export default class SearchResults extends React.Component {
componentDidMount() {
this.mounted = true;
SearchStore.addSearchChangeListener(this.onChange);
+ ChannelStore.addChangeListener(this.onChange);
this.resize();
window.addEventListener('resize', this.handleResize);
}
+ shouldComponentUpdate(nextProps, nextState) {
+ return !Utils.areObjectsEqual(this.props, nextProps) || !Utils.areObjectsEqual(this.state, nextState);
+ }
+
componentDidUpdate() {
this.resize();
}
componentWillUnmount() {
SearchStore.removeSearchChangeListener(this.onChange);
+ ChannelStore.removeChangeListener(this.onChange);
this.mounted = false;
window.removeEventListener('resize', this.handleResize);
}
@@ -56,10 +78,7 @@ export default class SearchResults extends React.Component {
onChange() {
if (this.mounted) {
- var newState = getStateFromStores();
- if (!Utils.areObjectsEqual(newState, this.state)) {
- this.setState(newState);
- }
+ this.setState(getStateFromStores());
}
}
@@ -116,6 +135,7 @@ export default class SearchResults extends React.Component {
return (
<SearchResultsItem
key={post.id}
+ channel={this.state.channels.get(post.channel_id)}
post={post}
term={searchTerm}
isMentionSearch={this.props.isMentionSearch}