From ac762f2277402c06f209ca3c8e0416d16916e991 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Tue, 24 Nov 2015 12:30:12 -0500 Subject: Replaced SearchAutocomplete with new suggestion components --- web/react/components/search_channel_provider.jsx | 71 ++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 web/react/components/search_channel_provider.jsx (limited to 'web/react/components/search_channel_provider.jsx') diff --git a/web/react/components/search_channel_provider.jsx b/web/react/components/search_channel_provider.jsx new file mode 100644 index 000000000..5c7ffac2e --- /dev/null +++ b/web/react/components/search_channel_provider.jsx @@ -0,0 +1,71 @@ +// 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 ( +
+ {item.name} +
+ ); + } +} + +SearchChannelSuggestion.propTypes = { + item: React.PropTypes.object.isRequired, + isSelection: React.PropTypes.bool, + onClick: React.PropTypes.func +}; + +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); + } + } +} + +export default new SearchChannelProvider(); \ No newline at end of file -- cgit v1.2.3-1-g7c22 From 956d460b108f278b6cfbcb728241b89b992b2a55 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Mon, 30 Nov 2015 14:12:09 -0500 Subject: Changed SuggestionProviders to be regular objects and not singletons --- web/react/components/search_channel_provider.jsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'web/react/components/search_channel_provider.jsx') diff --git a/web/react/components/search_channel_provider.jsx b/web/react/components/search_channel_provider.jsx index 5c7ffac2e..6b2fa2d62 100644 --- a/web/react/components/search_channel_provider.jsx +++ b/web/react/components/search_channel_provider.jsx @@ -31,7 +31,7 @@ SearchChannelSuggestion.propTypes = { onClick: React.PropTypes.func }; -class SearchChannelProvider { +export default class SearchChannelProvider { handlePretextChanged(suggestionId, pretext) { const captured = (/\b(?:in|channel):\s*(\S*)$/i).exec(pretext); if (captured) { @@ -67,5 +67,3 @@ class SearchChannelProvider { } } } - -export default new SearchChannelProvider(); \ No newline at end of file -- cgit v1.2.3-1-g7c22