summaryrefslogtreecommitdiffstats
path: root/webapp/components/suggestion/channel_mention_provider.jsx
diff options
context:
space:
mode:
authorJoram Wilander <jwawilander@gmail.com>2016-12-20 09:08:58 -0500
committerChristopher Speller <crspeller@gmail.com>2016-12-20 09:08:58 -0500
commitbf3fec604fc4ad0fd53d38490c18d872bccd629d (patch)
tree345838245dd4781d890009cc043dfa2723251ed4 /webapp/components/suggestion/channel_mention_provider.jsx
parentd4b890fff10a459a39c2405d2e0f1ecf36b79542 (diff)
downloadchat-bf3fec604fc4ad0fd53d38490c18d872bccd629d.tar.gz
chat-bf3fec604fc4ad0fd53d38490c18d872bccd629d.tar.bz2
chat-bf3fec604fc4ad0fd53d38490c18d872bccd629d.zip
Remove autocomplete delay (#4819)
Diffstat (limited to 'webapp/components/suggestion/channel_mention_provider.jsx')
-rw-r--r--webapp/components/suggestion/channel_mention_provider.jsx91
1 files changed, 38 insertions, 53 deletions
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
+ });
+ }
);
}
}