diff options
author | Joram Wilander <jwawilander@gmail.com> | 2016-12-20 09:08:58 -0500 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2016-12-20 09:08:58 -0500 |
commit | bf3fec604fc4ad0fd53d38490c18d872bccd629d (patch) | |
tree | 345838245dd4781d890009cc043dfa2723251ed4 /webapp/components/suggestion/switch_channel_provider.jsx | |
parent | d4b890fff10a459a39c2405d2e0f1ecf36b79542 (diff) | |
download | chat-bf3fec604fc4ad0fd53d38490c18d872bccd629d.tar.gz chat-bf3fec604fc4ad0fd53d38490c18d872bccd629d.tar.bz2 chat-bf3fec604fc4ad0fd53d38490c18d872bccd629d.zip |
Remove autocomplete delay (#4819)
Diffstat (limited to 'webapp/components/suggestion/switch_channel_provider.jsx')
-rw-r--r-- | webapp/components/suggestion/switch_channel_provider.jsx | 133 |
1 files changed, 59 insertions, 74 deletions
diff --git a/webapp/components/suggestion/switch_channel_provider.jsx b/webapp/components/suggestion/switch_channel_provider.jsx index b41bc4f11..bf9e7c646 100644 --- a/webapp/components/suggestion/switch_channel_provider.jsx +++ b/webapp/components/suggestion/switch_channel_provider.jsx @@ -59,94 +59,79 @@ class SwitchChannelSuggestion extends Suggestion { } export default class SwitchChannelProvider { - constructor() { - this.timeoutId = ''; - } - - componentWillUnmount() { - clearTimeout(this.timeoutId); - } - handlePretextChanged(suggestionId, channelPrefix) { if (channelPrefix) { const allChannels = ChannelStore.getAll(); const channels = []; - function autocomplete() { - autocompleteUsers( - channelPrefix, - (users) => { - const currentId = UserStore.getCurrentId(); + autocompleteUsers( + channelPrefix, + (users) => { + const currentId = UserStore.getCurrentId(); - for (const id of Object.keys(allChannels)) { - const channel = allChannels[id]; - if (channel.display_name.toLowerCase().indexOf(channelPrefix.toLowerCase()) !== -1) { - channels.push(channel); - } + for (const id of Object.keys(allChannels)) { + const channel = allChannels[id]; + if (channel.display_name.toLowerCase().indexOf(channelPrefix.toLowerCase()) !== -1) { + channels.push(channel); } + } - const userMap = {}; - for (let i = 0; i < users.length; i++) { - const user = users[i]; - let displayName = `@${user.username} `; + const userMap = {}; + for (let i = 0; i < users.length; i++) { + const user = users[i]; + let displayName = `@${user.username} `; - if (user.id === currentId) { - continue; - } - - if ((user.first_name || user.last_name) && user.nickname) { - displayName += `- ${Utils.getFullName(user)} (${user.nickname})`; - } else if (user.nickname) { - displayName += `- (${user.nickname})`; - } else if (user.first_name || user.last_name) { - displayName += `- ${Utils.getFullName(user)}`; - } + if (user.id === currentId) { + continue; + } - const newChannel = { - display_name: displayName, - name: user.username, - id: user.id, - update_at: user.update_at, - type: Constants.DM_CHANNEL - }; - channels.push(newChannel); - userMap[user.id] = user; + if ((user.first_name || user.last_name) && user.nickname) { + displayName += `- ${Utils.getFullName(user)} (${user.nickname})`; + } else if (user.nickname) { + displayName += `- (${user.nickname})`; + } else if (user.first_name || user.last_name) { + displayName += `- ${Utils.getFullName(user)}`; } - channels.sort((a, b) => { - if (a.display_name === b.display_name) { - if (a.type !== Constants.DM_CHANNEL && b.type === Constants.DM_CHANNEL) { - return -1; - } else if (a.type === Constants.DM_CHANNEL && b.type !== Constants.DM_CHANNEL) { - return 1; - } - return a.name.localeCompare(b.name); - } - return a.display_name.localeCompare(b.display_name); - }); - - const channelNames = channels.map((channel) => channel.name); - - AppDispatcher.handleServerAction({ - type: ActionTypes.SUGGESTION_RECEIVED_SUGGESTIONS, - id: suggestionId, - matchedPretext: channelPrefix, - terms: channelNames, - items: channels, - component: SwitchChannelSuggestion - }); - - AppDispatcher.handleServerAction({ - type: ActionTypes.RECEIVED_PROFILES, - profiles: userMap - }); + const newChannel = { + display_name: displayName, + name: user.username, + id: user.id, + update_at: user.update_at, + type: Constants.DM_CHANNEL + }; + channels.push(newChannel); + userMap[user.id] = user; } - ); - } - this.timeoutId = setTimeout( - autocomplete.bind(this), - Constants.AUTOCOMPLETE_TIMEOUT + channels.sort((a, b) => { + if (a.display_name === b.display_name) { + if (a.type !== Constants.DM_CHANNEL && b.type === Constants.DM_CHANNEL) { + return -1; + } else if (a.type === Constants.DM_CHANNEL && b.type !== Constants.DM_CHANNEL) { + return 1; + } + return a.name.localeCompare(b.name); + } + return a.display_name.localeCompare(b.display_name); + }); + + const channelNames = channels.map((channel) => channel.name); + + AppDispatcher.handleServerAction({ + type: ActionTypes.SUGGESTION_RECEIVED_SUGGESTIONS, + id: suggestionId, + matchedPretext: channelPrefix, + terms: channelNames, + items: channels, + component: SwitchChannelSuggestion + }); + + AppDispatcher.handleServerAction({ + type: ActionTypes.RECEIVED_PROFILES, + profiles: userMap + }); + } ); } } |