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)

---
 .../components/suggestion/search_user_provider.jsx | 49 +++++++---------------
 1 file changed, 16 insertions(+), 33 deletions(-)

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

diff --git a/webapp/components/suggestion/search_user_provider.jsx b/webapp/components/suggestion/search_user_provider.jsx
index 2aa72aef5..6fce8edcf 100644
--- a/webapp/components/suggestion/search_user_provider.jsx
+++ b/webapp/components/suggestion/search_user_provider.jsx
@@ -8,7 +8,7 @@ import {autocompleteUsersInTeam} from 'actions/user_actions.jsx';
 import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
 import Client from 'client/web_client.jsx';
 import * as Utils from 'utils/utils.jsx';
-import {Constants, ActionTypes} from 'utils/constants.jsx';
+import {ActionTypes} from 'utils/constants.jsx';
 
 import React from 'react';
 
@@ -57,43 +57,26 @@ class SearchUserSuggestion extends Suggestion {
 }
 
 export default class SearchUserProvider {
-    constructor() {
-        this.timeoutId = '';
-    }
-
-    componentWillUnmount() {
-        clearTimeout(this.timeoutId);
-    }
-
     handlePretextChanged(suggestionId, pretext) {
-        clearTimeout(this.timeoutId);
-
         const captured = (/\bfrom:\s*(\S*)$/i).exec(pretext.toLowerCase());
         if (captured) {
             const usernamePrefix = captured[1];
 
-            function autocomplete() {
-                autocompleteUsersInTeam(
-                    usernamePrefix,
-                    (data) => {
-                        const users = data.in_team;
-                        const mentions = users.map((user) => user.username);
-
-                        AppDispatcher.handleServerAction({
-                            type: ActionTypes.SUGGESTION_RECEIVED_SUGGESTIONS,
-                            id: suggestionId,
-                            matchedPretext: usernamePrefix,
-                            terms: mentions,
-                            items: users,
-                            component: SearchUserSuggestion
-                        });
-                    }
-                );
-            }
-
-            this.timeoutId = setTimeout(
-                autocomplete.bind(this),
-                Constants.AUTOCOMPLETE_TIMEOUT
+            autocompleteUsersInTeam(
+                usernamePrefix,
+                (data) => {
+                    const users = data.in_team;
+                    const mentions = users.map((user) => user.username);
+
+                    AppDispatcher.handleServerAction({
+                        type: ActionTypes.SUGGESTION_RECEIVED_SUGGESTIONS,
+                        id: suggestionId,
+                        matchedPretext: usernamePrefix,
+                        terms: mentions,
+                        items: users,
+                        component: SearchUserSuggestion
+                    });
+                }
             );
         }
     }
-- 
cgit v1.2.3-1-g7c22

