summaryrefslogtreecommitdiffstats
path: root/web/react
diff options
context:
space:
mode:
authorCorey Hulen <corey@hulen.com>2016-02-09 08:35:25 -0800
committerCorey Hulen <corey@hulen.com>2016-02-09 08:35:25 -0800
commit7ba50278d380733a8e85c8c057a3b5e5c1477ba2 (patch)
tree349bbfa0b0fd5893401b4567bad35f2750b9f138 /web/react
parenta4cce1023cae299a808875c00d6427003145da7d (diff)
parentbe716c3b668c4b5de385befc0e6ed5ca2116beb6 (diff)
downloadchat-7ba50278d380733a8e85c8c057a3b5e5c1477ba2.tar.gz
chat-7ba50278d380733a8e85c8c057a3b5e5c1477ba2.tar.bz2
chat-7ba50278d380733a8e85c8c057a3b5e5c1477ba2.zip
Merge pull request #2099 from hmhealey/plt1883
PLT-1883 Update search result components when we receive channels
Diffstat (limited to 'web/react')
-rw-r--r--web/react/components/search_results.jsx30
-rw-r--r--web/react/components/search_results_item.jsx6
-rw-r--r--web/react/utils/utils.jsx22
3 files changed, 50 insertions, 8 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}
diff --git a/web/react/components/search_results_item.jsx b/web/react/components/search_results_item.jsx
index 544ba920a..d3533037f 100644
--- a/web/react/components/search_results_item.jsx
+++ b/web/react/components/search_results_item.jsx
@@ -1,7 +1,6 @@
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
-import ChannelStore from '../stores/channel_store.jsx';
import UserStore from '../stores/user_store.jsx';
import UserProfile from './user_profile.jsx';
import * as EventHelpers from '../dispatcher/event_helpers.jsx';
@@ -37,8 +36,8 @@ export default class SearchResultsItem extends React.Component {
}
render() {
- var channelName = '';
- var channel = ChannelStore.get(this.props.post.channel_id);
+ var channelName = null;
+ const channel = this.props.channel;
var timestamp = UserStore.getCurrentUser().update_at;
if (channel) {
@@ -136,6 +135,7 @@ export default class SearchResultsItem extends React.Component {
SearchResultsItem.propTypes = {
post: React.PropTypes.object,
+ channel: React.PropTypes.object,
isMentionSearch: React.PropTypes.bool,
term: React.PropTypes.string
};
diff --git a/web/react/utils/utils.jsx b/web/react/utils/utils.jsx
index c2487f290..e2a5b9620 100644
--- a/web/react/utils/utils.jsx
+++ b/web/react/utils/utils.jsx
@@ -392,6 +392,10 @@ export function areObjectsEqual(x, y) {
return x.toString() === y.toString();
}
+ if (x instanceof Map && y instanceof Map) {
+ return areMapsEqual(x, y);
+ }
+
// At last checking prototypes as good a we can
if (!(x instanceof Object && y instanceof Object)) {
return false;
@@ -456,6 +460,24 @@ export function areObjectsEqual(x, y) {
return true;
}
+export function areMapsEqual(a, b) {
+ if (a.size !== b.size) {
+ return false;
+ }
+
+ for (const [key, value] of a) {
+ if (!b.has(key)) {
+ return false;
+ }
+
+ if (!areObjectsEqual(value, b.get(key))) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
export function replaceHtmlEntities(text) {
var tagsToReplace = {
'&amp;': '&',