diff options
Diffstat (limited to 'src/console')
-rw-r--r-- | src/console/components/console.js | 7 | ||||
-rw-r--r-- | src/console/reducers/index.js | 51 |
2 files changed, 25 insertions, 33 deletions
diff --git a/src/console/components/console.js b/src/console/components/console.js index a9ae4ed..417c9f6 100644 --- a/src/console/components/console.js +++ b/src/console/components/console.js @@ -107,16 +107,15 @@ export default class ConsoleComponent { } } - onInput(e) { + async onInput(e) { this.store.dispatch(consoleActions.setConsoleText(e.target.value)); let source = e.target.value; - return browser.runtime.sendMessage({ + let completions = await browser.runtime.sendMessage({ type: messages.CONSOLE_QUERY_COMPLETIONS, text: source, - }).then((completions) => { - this.store.dispatch(consoleActions.setCompletions(source, completions)); }); + this.store.dispatch(consoleActions.setCompletions(source, completions)); } onInputShown(state) { diff --git a/src/console/reducers/index.js b/src/console/reducers/index.js index 2aec55c..71b0776 100644 --- a/src/console/reducers/index.js +++ b/src/console/reducers/index.js @@ -51,68 +51,61 @@ const nextConsoleText = (completions, group, item, defaults) => { return completions[group].items[item].content; }; +// eslint-disable-next-line max-lines-per-function export default function reducer(state = defaultState, action = {}) { switch (action.type) { case actions.CONSOLE_HIDE: - return Object.assign({}, state, { - mode: '', - }); + return { ...state, + mode: '', }; case actions.CONSOLE_SHOW_COMMAND: - return Object.assign({}, state, { + return { ...state, mode: 'command', consoleText: action.text, - completions: [] - }); + completions: []}; case actions.CONSOLE_SHOW_FIND: - return Object.assign({}, state, { + return { ...state, mode: 'find', consoleText: '', - completions: [] - }); + completions: []}; case actions.CONSOLE_SHOW_ERROR: - return Object.assign({}, state, { + return { ...state, mode: 'error', - messageText: action.text, - }); + messageText: action.text, }; case actions.CONSOLE_SHOW_INFO: - return Object.assign({}, state, { + return { ...state, mode: 'info', - messageText: action.text, - }); + messageText: action.text, }; case actions.CONSOLE_HIDE_COMMAND: - return Object.assign({}, state, { + return { + ...state, mode: state.mode === 'command' || state.mode === 'find' ? '' : state.mode, - }); + }; case actions.CONSOLE_SET_CONSOLE_TEXT: - return Object.assign({}, state, { - consoleText: action.consoleText, - }); + return { ...state, + consoleText: action.consoleText, }; case actions.CONSOLE_SET_COMPLETIONS: - return Object.assign({}, state, { + return { ...state, completions: action.completions, completionSource: action.completionSource, groupSelection: -1, - itemSelection: -1, - }); + itemSelection: -1, }; case actions.CONSOLE_COMPLETION_NEXT: { let next = nextSelection(state); - return Object.assign({}, state, { + return { ...state, groupSelection: next[0], itemSelection: next[1], consoleText: nextConsoleText( state.completions, next[0], next[1], - state.completionSource), - }); + state.completionSource), }; } case actions.CONSOLE_COMPLETION_PREV: { let next = prevSelection(state); - return Object.assign({}, state, { + return { ...state, groupSelection: next[0], itemSelection: next[1], consoleText: nextConsoleText( state.completions, next[0], next[1], - state.completionSource), - }); + state.completionSource), }; } default: return state; |