Этот коммит содержится в:
Joram Wilander
2016-12-20 09:08:58 -05:00
коммит произвёл Christopher Speller
родитель d4b890fff1
Коммит bf3fec604f
6 изменённых файлов: 175 добавлений и 269 удалений

Просмотреть файл

@@ -4,7 +4,6 @@
import Suggestion from './suggestion.jsx'; import Suggestion from './suggestion.jsx';
import ChannelStore from 'stores/channel_store.jsx'; import ChannelStore from 'stores/channel_store.jsx';
import SuggestionStore from 'stores/suggestion_store.jsx';
import {autocompleteUsersInChannel} from 'actions/user_actions.jsx'; import {autocompleteUsersInChannel} from 'actions/user_actions.jsx';
@@ -104,32 +103,13 @@ class AtMentionSuggestion extends Suggestion {
export default class AtMentionProvider { export default class AtMentionProvider {
constructor(channelId) { constructor(channelId) {
this.channelId = 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) { handlePretextChanged(suggestionId, pretext) {
const hadSuggestions = this.clearTimeout(this.timeoutId);
const captured = XRegExp.cache('(?:^|\\W)@([\\pL\\d\\-_.]*)$', 'i').exec(pretext.toLowerCase()); const captured = XRegExp.cache('(?:^|\\W)@([\\pL\\d\\-_.]*)$', 'i').exec(pretext.toLowerCase());
if (captured) { if (captured) {
const prefix = captured[1]; const prefix = captured[1];
function autocomplete() {
autocompleteUsersInChannel( autocompleteUsersInChannel(
prefix, prefix,
this.channelId, this.channelId,
@@ -167,16 +147,5 @@ export default class AtMentionProvider {
} }
); );
} }
this.timeoutId = setTimeout(
autocomplete.bind(this),
Constants.AUTOCOMPLETE_TIMEOUT
);
}
if (hadSuggestions) {
// Clear the suggestions since the user has now typed something invalid
SuggestionStore.clearSuggestions(suggestionId);
}
} }
} }

Просмотреть файл

@@ -50,20 +50,11 @@ class ChannelMentionSuggestion extends Suggestion {
} }
export default class ChannelMentionProvider { export default class ChannelMentionProvider {
constructor() {
this.timeoutId = '';
}
componentWillUnmount() {
clearTimeout(this.timeoutId);
}
handlePretextChanged(suggestionId, pretext) { handlePretextChanged(suggestionId, pretext) {
const captured = (/(^|\s)(~([^~]*))$/i).exec(pretext.toLowerCase()); const captured = (/(^|\s)(~([^~]*))$/i).exec(pretext.toLowerCase());
if (captured) { if (captured) {
const prefix = captured[3]; const prefix = captured[3];
function autocomplete() {
autocompleteChannels( autocompleteChannels(
prefix, prefix,
(data) => { (data) => {
@@ -109,11 +100,5 @@ export default class ChannelMentionProvider {
} }
); );
} }
this.timeoutId = setTimeout(
autocomplete.bind(this),
Constants.AUTOCOMPLETE_TIMEOUT
);
}
} }
} }

Просмотреть файл

@@ -33,20 +33,11 @@ class SearchChannelSuggestion extends Suggestion {
} }
export default class SearchChannelProvider { export default class SearchChannelProvider {
constructor() {
this.timeoutId = '';
}
componentWillUnmount() {
clearTimeout(this.timeoutId);
}
handlePretextChanged(suggestionId, pretext) { handlePretextChanged(suggestionId, pretext) {
const captured = (/\b(?:in|channel):\s*(\S*)$/i).exec(pretext.toLowerCase()); const captured = (/\b(?:in|channel):\s*(\S*)$/i).exec(pretext.toLowerCase());
if (captured) { if (captured) {
const channelPrefix = captured[1]; const channelPrefix = captured[1];
function autocomplete() {
autocompleteChannels( autocompleteChannels(
channelPrefix, channelPrefix,
(data) => { (data) => {
@@ -86,11 +77,5 @@ export default class SearchChannelProvider {
} }
); );
} }
this.timeoutId = setTimeout(
autocomplete.bind(this),
Constants.AUTOCOMPLETE_TIMEOUT
);
}
} }
} }

Просмотреть файл

@@ -8,7 +8,7 @@ import {autocompleteUsersInTeam} from 'actions/user_actions.jsx';
import AppDispatcher from 'dispatcher/app_dispatcher.jsx'; import AppDispatcher from 'dispatcher/app_dispatcher.jsx';
import Client from 'client/web_client.jsx'; import Client from 'client/web_client.jsx';
import * as Utils from 'utils/utils.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'; import React from 'react';
@@ -57,22 +57,11 @@ class SearchUserSuggestion extends Suggestion {
} }
export default class SearchUserProvider { export default class SearchUserProvider {
constructor() {
this.timeoutId = '';
}
componentWillUnmount() {
clearTimeout(this.timeoutId);
}
handlePretextChanged(suggestionId, pretext) { handlePretextChanged(suggestionId, pretext) {
clearTimeout(this.timeoutId);
const captured = (/\bfrom:\s*(\S*)$/i).exec(pretext.toLowerCase()); const captured = (/\bfrom:\s*(\S*)$/i).exec(pretext.toLowerCase());
if (captured) { if (captured) {
const usernamePrefix = captured[1]; const usernamePrefix = captured[1];
function autocomplete() {
autocompleteUsersInTeam( autocompleteUsersInTeam(
usernamePrefix, usernamePrefix,
(data) => { (data) => {
@@ -90,11 +79,5 @@ export default class SearchUserProvider {
} }
); );
} }
this.timeoutId = setTimeout(
autocomplete.bind(this),
Constants.AUTOCOMPLETE_TIMEOUT
);
}
} }
} }

Просмотреть файл

@@ -59,20 +59,11 @@ class SwitchChannelSuggestion extends Suggestion {
} }
export default class SwitchChannelProvider { export default class SwitchChannelProvider {
constructor() {
this.timeoutId = '';
}
componentWillUnmount() {
clearTimeout(this.timeoutId);
}
handlePretextChanged(suggestionId, channelPrefix) { handlePretextChanged(suggestionId, channelPrefix) {
if (channelPrefix) { if (channelPrefix) {
const allChannels = ChannelStore.getAll(); const allChannels = ChannelStore.getAll();
const channels = []; const channels = [];
function autocomplete() {
autocompleteUsers( autocompleteUsers(
channelPrefix, channelPrefix,
(users) => { (users) => {
@@ -143,11 +134,5 @@ export default class SwitchChannelProvider {
} }
); );
} }
this.timeoutId = setTimeout(
autocomplete.bind(this),
Constants.AUTOCOMPLETE_TIMEOUT
);
}
} }
} }

Просмотреть файл

@@ -865,7 +865,6 @@ export const Constants = {
MENTION_SPECIAL: 'mention.special', MENTION_SPECIAL: 'mention.special',
DEFAULT_NOTIFICATION_DURATION: 5000, DEFAULT_NOTIFICATION_DURATION: 5000,
STATUS_INTERVAL: 60000, STATUS_INTERVAL: 60000,
AUTOCOMPLETE_TIMEOUT: 100,
SEARCH_TIMEOUT_MILLISECONDS: 100 SEARCH_TIMEOUT_MILLISECONDS: 100
}; };