summaryrefslogtreecommitdiffstats
path: root/web/react/components/search_channel_provider.jsx
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2015-12-03 08:13:32 -0500
committerChristopher Speller <crspeller@gmail.com>2015-12-03 08:13:32 -0500
commit6aa316a75a67f191f7a6db7b6fae642369e51f81 (patch)
treee53adb7997a325a4fb48ef5b3b31a4523e39ae7d /web/react/components/search_channel_provider.jsx
parent0a38ec5796391d0daf7b7874859108a54c20ec5f (diff)
parent956d460b108f278b6cfbcb728241b89b992b2a55 (diff)
downloadchat-6aa316a75a67f191f7a6db7b6fae642369e51f81.tar.gz
chat-6aa316a75a67f191f7a6db7b6fae642369e51f81.tar.bz2
chat-6aa316a75a67f191f7a6db7b6fae642369e51f81.zip
Merge pull request #1540 from hmhealey/plt1297
PLT-1297 Replaced SearchAutocomplete with new suggestion components
Diffstat (limited to 'web/react/components/search_channel_provider.jsx')
-rw-r--r--web/react/components/search_channel_provider.jsx69
1 files changed, 69 insertions, 0 deletions
diff --git a/web/react/components/search_channel_provider.jsx b/web/react/components/search_channel_provider.jsx
new file mode 100644
index 000000000..6b2fa2d62
--- /dev/null
+++ b/web/react/components/search_channel_provider.jsx
@@ -0,0 +1,69 @@
+// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
+// See License.txt for license information.
+
+import ChannelStore from '../stores/channel_store.jsx';
+import Constants from '../utils/constants.jsx';
+import SuggestionStore from '../stores/suggestion_store.jsx';
+
+class SearchChannelSuggestion extends React.Component {
+ render() {
+ const {item, isSelection, onClick} = this.props;
+
+ let className = 'search-autocomplete__item';
+ if (isSelection) {
+ className += ' selected';
+ }
+
+ return (
+ <div
+ onClick={onClick}
+ className={className}
+ >
+ {item.name}
+ </div>
+ );
+ }
+}
+
+SearchChannelSuggestion.propTypes = {
+ item: React.PropTypes.object.isRequired,
+ isSelection: React.PropTypes.bool,
+ onClick: React.PropTypes.func
+};
+
+export default class SearchChannelProvider {
+ handlePretextChanged(suggestionId, pretext) {
+ const captured = (/\b(?:in|channel):\s*(\S*)$/i).exec(pretext);
+ if (captured) {
+ const channelPrefix = captured[1];
+
+ const channels = ChannelStore.getAll();
+ const publicChannels = [];
+ const privateChannels = [];
+
+ for (const id of Object.keys(channels)) {
+ const channel = channels[id];
+
+ // don't show direct channels
+ if (channel.type !== Constants.DM_CHANNEL && channel.name.startsWith(channelPrefix)) {
+ if (channel.type === Constants.OPEN_CHANNEL) {
+ publicChannels.push(channel);
+ } else {
+ privateChannels.push(channel);
+ }
+ }
+ }
+
+ publicChannels.sort((a, b) => a.name.localeCompare(b.name));
+ const publicChannelNames = publicChannels.map((channel) => channel.name);
+
+ privateChannels.sort((a, b) => a.name.localeCompare(b.name));
+ const privateChannelNames = privateChannels.map((channel) => channel.name);
+
+ SuggestionStore.setMatchedPretext(suggestionId, channelPrefix);
+
+ SuggestionStore.addSuggestions(suggestionId, publicChannelNames, publicChannels, SearchChannelSuggestion);
+ SuggestionStore.addSuggestions(suggestionId, privateChannelNames, privateChannels, SearchChannelSuggestion);
+ }
+ }
+}