From bf3fec604fc4ad0fd53d38490c18d872bccd629d Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Tue, 20 Dec 2016 09:08:58 -0500 Subject: Remove autocomplete delay (#4819) --- .../components/suggestion/at_mention_provider.jsx | 95 ++++++++-------------- 1 file changed, 32 insertions(+), 63 deletions(-) (limited to 'webapp/components/suggestion/at_mention_provider.jsx') diff --git a/webapp/components/suggestion/at_mention_provider.jsx b/webapp/components/suggestion/at_mention_provider.jsx index f1b36d697..9a5e103ad 100644 --- a/webapp/components/suggestion/at_mention_provider.jsx +++ b/webapp/components/suggestion/at_mention_provider.jsx @@ -4,7 +4,6 @@ import Suggestion from './suggestion.jsx'; import ChannelStore from 'stores/channel_store.jsx'; -import SuggestionStore from 'stores/suggestion_store.jsx'; import {autocompleteUsersInChannel} from 'actions/user_actions.jsx'; @@ -104,79 +103,49 @@ class AtMentionSuggestion extends Suggestion { export default class AtMentionProvider { constructor(channelId) { this.channelId = channelId; - this.timeoutId = ''; - } - - componentWillUnmount() { - this.clearTimeout(this.timeoutId); - } - - clearTimeout() { - if (this.timeoutId) { - clearTimeout(this.timeoutId); - this.timeoutId = ''; - - return true; - } - - return false; } handlePretextChanged(suggestionId, pretext) { - const hadSuggestions = this.clearTimeout(this.timeoutId); - const captured = XRegExp.cache('(?:^|\\W)@([\\pL\\d\\-_.]*)$', 'i').exec(pretext.toLowerCase()); if (captured) { const prefix = captured[1]; - function autocomplete() { - autocompleteUsersInChannel( - prefix, - this.channelId, - (data) => { - const members = data.in_channel; - for (const id of Object.keys(members)) { - members[id].type = Constants.MENTION_MEMBERS; - } - - const nonmembers = data.out_of_channel; - for (const id of Object.keys(nonmembers)) { - nonmembers[id].type = Constants.MENTION_NONMEMBERS; - } - - let specialMentions = []; - if (!pretext.startsWith('/msg')) { - specialMentions = ['here', 'channel', 'all'].filter((item) => { - return item.startsWith(prefix); - }).map((name) => { - return {username: name, type: Constants.MENTION_SPECIAL}; - }); - } - - const users = members.concat(specialMentions).concat(nonmembers); - const mentions = users.map((user) => '@' + user.username); - - AppDispatcher.handleServerAction({ - type: ActionTypes.SUGGESTION_RECEIVED_SUGGESTIONS, - id: suggestionId, - matchedPretext: `@${captured[1]}`, - terms: mentions, - items: users, - component: AtMentionSuggestion + autocompleteUsersInChannel( + prefix, + this.channelId, + (data) => { + const members = data.in_channel; + for (const id of Object.keys(members)) { + members[id].type = Constants.MENTION_MEMBERS; + } + + const nonmembers = data.out_of_channel; + for (const id of Object.keys(nonmembers)) { + nonmembers[id].type = Constants.MENTION_NONMEMBERS; + } + + let specialMentions = []; + if (!pretext.startsWith('/msg')) { + specialMentions = ['here', 'channel', 'all'].filter((item) => { + return item.startsWith(prefix); + }).map((name) => { + return {username: name, type: Constants.MENTION_SPECIAL}; }); } - ); - } - this.timeoutId = setTimeout( - autocomplete.bind(this), - Constants.AUTOCOMPLETE_TIMEOUT + const users = members.concat(specialMentions).concat(nonmembers); + const mentions = users.map((user) => '@' + user.username); + + AppDispatcher.handleServerAction({ + type: ActionTypes.SUGGESTION_RECEIVED_SUGGESTIONS, + id: suggestionId, + matchedPretext: `@${captured[1]}`, + terms: mentions, + items: users, + component: AtMentionSuggestion + }); + } ); } - - if (hadSuggestions) { - // Clear the suggestions since the user has now typed something invalid - SuggestionStore.clearSuggestions(suggestionId); - } } } -- cgit v1.2.3-1-g7c22