summaryrefslogtreecommitdiffstats
path: root/web/react/components/suggestion
diff options
context:
space:
mode:
authorhmhealey <harrisonmhealey@gmail.com>2015-12-02 09:21:58 -0500
committerhmhealey <harrisonmhealey@gmail.com>2015-12-02 09:21:58 -0500
commit07f0df6af428a56a4abedde841a0813e2802cd2b (patch)
tree7f2b7e913ac91ed6ee1bacaa0831c37b71c549d8 /web/react/components/suggestion
parent06e0919bca7ee4280c6eed58838ca2be10e7b4fb (diff)
downloadchat-07f0df6af428a56a4abedde841a0813e2802cd2b.tar.gz
chat-07f0df6af428a56a4abedde841a0813e2802cd2b.tar.bz2
chat-07f0df6af428a56a4abedde841a0813e2802cd2b.zip
Moved action creation for suggestions
Diffstat (limited to 'web/react/components/suggestion')
-rw-r--r--web/react/components/suggestion/command_provider.jsx25
-rw-r--r--web/react/components/suggestion/suggestion_box.jsx23
-rw-r--r--web/react/components/suggestion/suggestion_list.jsx8
3 files changed, 9 insertions, 47 deletions
diff --git a/web/react/components/suggestion/command_provider.jsx b/web/react/components/suggestion/command_provider.jsx
index 34de3bfd1..a1f7901ef 100644
--- a/web/react/components/suggestion/command_provider.jsx
+++ b/web/react/components/suggestion/command_provider.jsx
@@ -1,8 +1,7 @@
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
-import AppDispatcher from '../../dispatcher/app_dispatcher.jsx';
-import * as Client from '../../utils/client.jsx';
+import * as AsyncClient from '../../utils/async_client.jsx';
import Constants from '../../utils/constants.jsx';
import SuggestionStore from '../../stores/suggestion_store.jsx';
@@ -42,27 +41,7 @@ export default class CommandProvider {
if (pretext.startsWith('/')) {
SuggestionStore.setMatchedPretext(suggestionId, pretext);
- Client.executeCommand(
- '',
- pretext,
- true,
- (data) => {
- this.handleCommandsReceived(suggestionId, pretext, data.suggestions);
- }
- );
+ AsyncClient.getSuggestedCommands(pretext, suggestionId, CommandSuggestion);
}
}
-
- handleCommandsReceived(suggestionId, matchedPretext, commandSuggestions) {
- const terms = commandSuggestions.map(({suggestion}) => suggestion);
-
- AppDispatcher.handleServerAction({
- type: Constants.ActionTypes.SUGGESTION_RECEIVED_SUGGESTIONS,
- id: suggestionId,
- matchedPretext,
- terms,
- items: commandSuggestions,
- component: CommandSuggestion
- });
- }
}
diff --git a/web/react/components/suggestion/suggestion_box.jsx b/web/react/components/suggestion/suggestion_box.jsx
index 22dbf1497..d8493f92a 100644
--- a/web/react/components/suggestion/suggestion_box.jsx
+++ b/web/react/components/suggestion/suggestion_box.jsx
@@ -1,8 +1,8 @@
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
-import AppDispatcher from '../../dispatcher/app_dispatcher.jsx';
import Constants from '../../utils/constants.jsx';
+import * as EventHelpers from '../../dispatcher/event_helpers.jsx';
import SuggestionStore from '../../stores/suggestion_store.jsx';
import * as Utils from '../../utils/utils.jsx';
@@ -79,11 +79,7 @@ export default class SuggestionBox extends React.Component {
const caret = Utils.getCaretPosition(textbox);
const pretext = textbox.value.substring(0, caret);
- AppDispatcher.handleViewAction({
- type: ActionTypes.SUGGESTION_PRETEXT_CHANGED,
- id: this.suggestionId,
- pretext
- });
+ EventHelpers.emitSuggestionPretextChanged(this.suggestionId, pretext);
if (this.props.onUserInput) {
this.props.onUserInput(textbox.value);
@@ -115,22 +111,13 @@ export default class SuggestionBox extends React.Component {
handleKeyDown(e) {
if (SuggestionStore.hasSuggestions(this.suggestionId)) {
if (e.which === KeyCodes.UP) {
- AppDispatcher.handleViewAction({
- type: ActionTypes.SUGGESTION_SELECT_PREVIOUS,
- id: this.suggestionId
- });
+ EventHelpers.emitSelectPreviousSuggestion(this.suggestionId);
e.preventDefault();
} else if (e.which === KeyCodes.DOWN) {
- AppDispatcher.handleViewAction({
- type: ActionTypes.SUGGESTION_SELECT_NEXT,
- id: this.suggestionId
- });
+ EventHelpers.emitSelectNextSuggestion(this.suggestionId);
e.preventDefault();
} else if (e.which === KeyCodes.SPACE || e.which === KeyCodes.ENTER) {
- AppDispatcher.handleViewAction({
- type: ActionTypes.SUGGESTION_COMPLETE_WORD,
- id: this.suggestionId
- });
+ EventHelpers.emitCompleteWordSuggestion(this.suggestionId);
e.preventDefault();
} else if (this.props.onKeyDown) {
this.props.onKeyDown(e);
diff --git a/web/react/components/suggestion/suggestion_list.jsx b/web/react/components/suggestion/suggestion_list.jsx
index cd75f36c5..290e0eec6 100644
--- a/web/react/components/suggestion/suggestion_list.jsx
+++ b/web/react/components/suggestion/suggestion_list.jsx
@@ -1,8 +1,8 @@
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
-import AppDispatcher from '../../dispatcher/app_dispatcher.jsx';
import Constants from '../../utils/constants.jsx';
+import * as EventHelpers from '../../dispatcher/event_helpers.jsx';
import SuggestionStore from '../../stores/suggestion_store.jsx';
export default class SuggestionList extends React.Component {
@@ -37,11 +37,7 @@ export default class SuggestionList extends React.Component {
}
handleItemClick(term, e) {
- AppDispatcher.handleViewAction({
- type: Constants.ActionTypes.SUGGESTION_COMPLETE_WORD,
- id: this.props.suggestionId,
- term
- });
+ EventHelpers.emitCompleteWordSuggestion(this.props.suggestionId, term);
e.preventDefault();
}