Moved action creation for suggestions

Этот коммит содержится в:
hmhealey
2015-12-02 09:21:58 -05:00
родитель 06e0919bca
Коммит 07f0df6af4
5 изменённых файлов: 63 добавлений и 47 удалений

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

@@ -1,8 +1,7 @@
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information. // See License.txt for license information.
import AppDispatcher from '../../dispatcher/app_dispatcher.jsx'; import * as AsyncClient from '../../utils/async_client.jsx';
import * as Client from '../../utils/client.jsx';
import Constants from '../../utils/constants.jsx'; import Constants from '../../utils/constants.jsx';
import SuggestionStore from '../../stores/suggestion_store.jsx'; import SuggestionStore from '../../stores/suggestion_store.jsx';
@@ -42,27 +41,7 @@ export default class CommandProvider {
if (pretext.startsWith('/')) { if (pretext.startsWith('/')) {
SuggestionStore.setMatchedPretext(suggestionId, pretext); SuggestionStore.setMatchedPretext(suggestionId, pretext);
Client.executeCommand( AsyncClient.getSuggestedCommands(pretext, suggestionId, CommandSuggestion);
'',
pretext,
true,
(data) => {
this.handleCommandsReceived(suggestionId, pretext, data.suggestions);
}
);
} }
} }
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
});
}
} }

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

@@ -1,8 +1,8 @@
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information. // See License.txt for license information.
import AppDispatcher from '../../dispatcher/app_dispatcher.jsx';
import Constants from '../../utils/constants.jsx'; import Constants from '../../utils/constants.jsx';
import * as EventHelpers from '../../dispatcher/event_helpers.jsx';
import SuggestionStore from '../../stores/suggestion_store.jsx'; import SuggestionStore from '../../stores/suggestion_store.jsx';
import * as Utils from '../../utils/utils.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 caret = Utils.getCaretPosition(textbox);
const pretext = textbox.value.substring(0, caret); const pretext = textbox.value.substring(0, caret);
AppDispatcher.handleViewAction({ EventHelpers.emitSuggestionPretextChanged(this.suggestionId, pretext);
type: ActionTypes.SUGGESTION_PRETEXT_CHANGED,
id: this.suggestionId,
pretext
});
if (this.props.onUserInput) { if (this.props.onUserInput) {
this.props.onUserInput(textbox.value); this.props.onUserInput(textbox.value);
@@ -115,22 +111,13 @@ export default class SuggestionBox extends React.Component {
handleKeyDown(e) { handleKeyDown(e) {
if (SuggestionStore.hasSuggestions(this.suggestionId)) { if (SuggestionStore.hasSuggestions(this.suggestionId)) {
if (e.which === KeyCodes.UP) { if (e.which === KeyCodes.UP) {
AppDispatcher.handleViewAction({ EventHelpers.emitSelectPreviousSuggestion(this.suggestionId);
type: ActionTypes.SUGGESTION_SELECT_PREVIOUS,
id: this.suggestionId
});
e.preventDefault(); e.preventDefault();
} else if (e.which === KeyCodes.DOWN) { } else if (e.which === KeyCodes.DOWN) {
AppDispatcher.handleViewAction({ EventHelpers.emitSelectNextSuggestion(this.suggestionId);
type: ActionTypes.SUGGESTION_SELECT_NEXT,
id: this.suggestionId
});
e.preventDefault(); e.preventDefault();
} else if (e.which === KeyCodes.SPACE || e.which === KeyCodes.ENTER) { } else if (e.which === KeyCodes.SPACE || e.which === KeyCodes.ENTER) {
AppDispatcher.handleViewAction({ EventHelpers.emitCompleteWordSuggestion(this.suggestionId);
type: ActionTypes.SUGGESTION_COMPLETE_WORD,
id: this.suggestionId
});
e.preventDefault(); e.preventDefault();
} else if (this.props.onKeyDown) { } else if (this.props.onKeyDown) {
this.props.onKeyDown(e); this.props.onKeyDown(e);

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

@@ -1,8 +1,8 @@
// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // Copyright (c) 2015 Mattermost, Inc. All Rights Reserved.
// See License.txt for license information. // See License.txt for license information.
import AppDispatcher from '../../dispatcher/app_dispatcher.jsx';
import Constants from '../../utils/constants.jsx'; import Constants from '../../utils/constants.jsx';
import * as EventHelpers from '../../dispatcher/event_helpers.jsx';
import SuggestionStore from '../../stores/suggestion_store.jsx'; import SuggestionStore from '../../stores/suggestion_store.jsx';
export default class SuggestionList extends React.Component { export default class SuggestionList extends React.Component {
@@ -37,11 +37,7 @@ export default class SuggestionList extends React.Component {
} }
handleItemClick(term, e) { handleItemClick(term, e) {
AppDispatcher.handleViewAction({ EventHelpers.emitCompleteWordSuggestion(this.props.suggestionId, term);
type: Constants.ActionTypes.SUGGESTION_COMPLETE_WORD,
id: this.props.suggestionId,
term
});
e.preventDefault(); e.preventDefault();
} }

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

@@ -111,3 +111,33 @@ export function showRegisterAppModal() {
value: true value: true
}); });
} }
export function emitSuggestionPretextChanged(suggestionId, pretext) {
AppDispatcher.handleViewAction({
type: ActionTypes.SUGGESTION_PRETEXT_CHANGED,
id: suggestionId,
pretext
});
}
export function emitSelectNextSuggestion(suggestionId) {
AppDispatcher.handleViewAction({
type: ActionTypes.SUGGESTION_SELECT_NEXT,
id: suggestionId
});
}
export function emitSelectPreviousSuggestion(suggestionId) {
AppDispatcher.handleViewAction({
type: ActionTypes.SUGGESTION_SELECT_PREVIOUS,
id: suggestionId
});
}
export function emitCompleteWordSuggestion(suggestionId, term = '') {
AppDispatcher.handleViewAction({
type: Constants.ActionTypes.SUGGESTION_COMPLETE_WORD,
id: suggestionId,
term
});
}

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

@@ -731,3 +731,27 @@ export function savePreferences(preferences, success, error) {
} }
); );
} }
export function getSuggestedCommands(command, suggestionId, component) {
client.executeCommand(
'',
command,
true,
(data) => {
// pull out the suggested commands from the returned data
const terms = data.suggestions.map((suggestion) => suggestion.suggestion);
AppDispatcher.handleServerAction({
type: ActionTypes.SUGGESTION_RECEIVED_SUGGESTIONS,
id: suggestionId,
matchedPretext: command,
terms,
items: data.suggestions,
component
});
},
(err) => {
dispatchError(err, 'getCommandSuggestions');
}
);
}