From bf3fec604fc4ad0fd53d38490c18d872bccd629d Mon Sep 17 00:00:00 2001
From: Joram Wilander <jwawilander@gmail.com>
Date: Tue, 20 Dec 2016 09:08:58 -0500
Subject: Remove autocomplete delay (#4819)

---
 .../suggestion/channel_mention_provider.jsx        | 91 +++++++++-------------
 1 file changed, 38 insertions(+), 53 deletions(-)

(limited to 'webapp/components/suggestion/channel_mention_provider.jsx')

diff --git a/webapp/components/suggestion/channel_mention_provider.jsx b/webapp/components/suggestion/channel_mention_provider.jsx
index c644d1a9f..7c781a2f7 100644
--- a/webapp/components/suggestion/channel_mention_provider.jsx
+++ b/webapp/components/suggestion/channel_mention_provider.jsx
@@ -50,69 +50,54 @@ class ChannelMentionSuggestion extends Suggestion {
 }
 
 export default class ChannelMentionProvider {
-    constructor() {
-        this.timeoutId = '';
-    }
-
-    componentWillUnmount() {
-        clearTimeout(this.timeoutId);
-    }
-
     handlePretextChanged(suggestionId, pretext) {
         const captured = (/(^|\s)(~([^~]*))$/i).exec(pretext.toLowerCase());
         if (captured) {
             const prefix = captured[3];
 
-            function autocomplete() {
-                autocompleteChannels(
-                    prefix,
-                    (data) => {
-                        const channels = data;
-
-                        // Wrap channels in an outer object to avoid overwriting the 'type' property.
-                        const wrappedChannels = [];
-                        const wrappedMoreChannels = [];
-                        const moreChannels = [];
-                        channels.forEach((item) => {
-                            if (ChannelStore.get(item.id)) {
-                                wrappedChannels.push({
-                                    type: Constants.MENTION_CHANNELS,
-                                    channel: item
-                                });
-                                return;
-                            }
-
-                            wrappedMoreChannels.push({
-                                type: Constants.MENTION_MORE_CHANNELS,
+            autocompleteChannels(
+                prefix,
+                (data) => {
+                    const channels = data;
+
+                    // Wrap channels in an outer object to avoid overwriting the 'type' property.
+                    const wrappedChannels = [];
+                    const wrappedMoreChannels = [];
+                    const moreChannels = [];
+                    channels.forEach((item) => {
+                        if (ChannelStore.get(item.id)) {
+                            wrappedChannels.push({
+                                type: Constants.MENTION_CHANNELS,
                                 channel: item
                             });
+                            return;
+                        }
 
-                            moreChannels.push(item);
-                        });
-
-                        const wrapped = wrappedChannels.concat(wrappedMoreChannels);
-                        const mentions = wrapped.map((item) => '~' + item.channel.name);
-
-                        AppDispatcher.handleServerAction({
-                            type: ActionTypes.RECEIVED_MORE_CHANNELS,
-                            channels: moreChannels
-                        });
-
-                        AppDispatcher.handleServerAction({
-                            type: ActionTypes.SUGGESTION_RECEIVED_SUGGESTIONS,
-                            id: suggestionId,
-                            matchedPretext: captured[2],
-                            terms: mentions,
-                            items: wrapped,
-                            component: ChannelMentionSuggestion
+                        wrappedMoreChannels.push({
+                            type: Constants.MENTION_MORE_CHANNELS,
+                            channel: item
                         });
-                    }
-                );
-            }
 
-            this.timeoutId = setTimeout(
-                autocomplete.bind(this),
-                Constants.AUTOCOMPLETE_TIMEOUT
+                        moreChannels.push(item);
+                    });
+
+                    const wrapped = wrappedChannels.concat(wrappedMoreChannels);
+                    const mentions = wrapped.map((item) => '~' + item.channel.name);
+
+                    AppDispatcher.handleServerAction({
+                        type: ActionTypes.RECEIVED_MORE_CHANNELS,
+                        channels: moreChannels
+                    });
+
+                    AppDispatcher.handleServerAction({
+                        type: ActionTypes.SUGGESTION_RECEIVED_SUGGESTIONS,
+                        id: suggestionId,
+                        matchedPretext: captured[2],
+                        terms: mentions,
+                        items: wrapped,
+                        component: ChannelMentionSuggestion
+                    });
+                }
             );
         }
     }
-- 
cgit v1.2.3-1-g7c22

