use mode in console message
This commit is contained in:
parent
f6996a2274
commit
b0d2b53281
11 changed files with 36 additions and 43 deletions
|
@ -48,7 +48,7 @@ export default class BackgroundComponent {
|
||||||
tabActions.openToTab(message.url, sender.tab), sender);
|
tabActions.openToTab(message.url, sender.tab), sender);
|
||||||
case messages.CONSOLE_BLURRED:
|
case messages.CONSOLE_BLURRED:
|
||||||
return browser.tabs.sendMessage(sender.tab.id, {
|
return browser.tabs.sendMessage(sender.tab.id, {
|
||||||
type: messages.CONSOLE_HIDE,
|
type: messages.CONSOLE_HIDE_COMMAND,
|
||||||
});
|
});
|
||||||
case messages.CONSOLE_ENTERED:
|
case messages.CONSOLE_ENTERED:
|
||||||
return commands.exec(message.text, this.settings).catch((e) => {
|
return commands.exec(message.text, this.settings).catch((e) => {
|
||||||
|
|
|
@ -14,9 +14,9 @@ const showError = (text) => {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const hide = () => {
|
const hideCommand = () => {
|
||||||
return {
|
return {
|
||||||
type: actions.CONSOLE_HIDE
|
type: actions.CONSOLE_HIDE_COMMAND,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -40,5 +40,6 @@ const completionPrev = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
export {
|
export {
|
||||||
showCommand, showError, hide, setCompletions, completionNext, completionPrev
|
showCommand, showError, hideCommand,
|
||||||
|
setCompletions, completionNext, completionPrev
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,7 +3,7 @@ export default {
|
||||||
CONSOLE_SHOW_COMMAND: 'console.show.command',
|
CONSOLE_SHOW_COMMAND: 'console.show.command',
|
||||||
CONSOLE_SET_COMPLETIONS: 'console.set.completions',
|
CONSOLE_SET_COMPLETIONS: 'console.set.completions',
|
||||||
CONSOLE_SHOW_ERROR: 'console.show.error',
|
CONSOLE_SHOW_ERROR: 'console.show.error',
|
||||||
CONSOLE_HIDE: 'console.hide',
|
CONSOLE_HIDE_COMMAND: 'console.hide.command',
|
||||||
CONSOLE_COMPLETION_NEXT: 'console.completion.next',
|
CONSOLE_COMPLETION_NEXT: 'console.completion.next',
|
||||||
CONSOLE_COMPLETION_PREV: 'console.completion.prev',
|
CONSOLE_COMPLETION_PREV: 'console.completion.prev',
|
||||||
};
|
};
|
||||||
|
|
|
@ -72,14 +72,14 @@ export default class ConsoleComponent {
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
let state = this.store.getState();
|
let state = this.store.getState();
|
||||||
if (!this.prevState.commandShown && state.commandShown) {
|
if (this.prevState.mode !== 'command' && state.mode === 'command') {
|
||||||
this.showCommand(state.commandText);
|
this.showCommand(state.commandText);
|
||||||
} else if (!state.commandShown) {
|
} else if (state.mode !== 'command') {
|
||||||
this.hideCommand();
|
this.hideCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (state.errorShown) {
|
if (state.mode === 'error') {
|
||||||
this.setErrorText(state.errorText);
|
this.setErrorText(state.messageText);
|
||||||
this.showError();
|
this.showError();
|
||||||
} else {
|
} else {
|
||||||
this.hideError();
|
this.hideError();
|
||||||
|
|
|
@ -28,7 +28,7 @@ browser.runtime.onMessage.addListener((action) => {
|
||||||
return store.dispatch(consoleActions.showCommand(action.command));
|
return store.dispatch(consoleActions.showCommand(action.command));
|
||||||
case messages.CONSOLE_SHOW_ERROR:
|
case messages.CONSOLE_SHOW_ERROR:
|
||||||
return store.dispatch(consoleActions.showError(action.text));
|
return store.dispatch(consoleActions.showError(action.text));
|
||||||
case messages.CONSOLE_HIDE:
|
case messages.CONSOLE_HIDE_COMMAND:
|
||||||
return store.dispatch(consoleActions.hide(action.command));
|
return store.dispatch(consoleActions.hideCommand());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
import actions from 'console/actions';
|
import actions from 'console/actions';
|
||||||
|
|
||||||
const defaultState = {
|
const defaultState = {
|
||||||
errorShown: false,
|
mode: '',
|
||||||
errorText: '',
|
messageText: '',
|
||||||
commandShown: false,
|
|
||||||
commandText: '',
|
commandText: '',
|
||||||
completions: [],
|
completions: [],
|
||||||
groupSelection: -1,
|
groupSelection: -1,
|
||||||
|
@ -48,25 +47,19 @@ export default function reducer(state = defaultState, action = {}) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case actions.CONSOLE_SHOW_COMMAND:
|
case actions.CONSOLE_SHOW_COMMAND:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
commandShown: true,
|
mode: 'command',
|
||||||
commandText: action.text,
|
commandText: action.text,
|
||||||
errorShown: false,
|
errorShown: false,
|
||||||
completions: []
|
completions: []
|
||||||
});
|
});
|
||||||
case actions.CONSOLE_SHOW_ERROR:
|
case actions.CONSOLE_SHOW_ERROR:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
errorText: action.text,
|
mode: 'error',
|
||||||
errorShown: true,
|
messageText: action.text,
|
||||||
commandShown: false,
|
|
||||||
});
|
});
|
||||||
case actions.CONSOLE_HIDE:
|
case actions.CONSOLE_HIDE_COMMAND:
|
||||||
if (state.errorShown) {
|
|
||||||
// keep error message if shown
|
|
||||||
return state;
|
|
||||||
}
|
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
errorShown: false,
|
mode: state.mode === 'command' ? '' : state.mode,
|
||||||
commandShown: false
|
|
||||||
});
|
});
|
||||||
case actions.CONSOLE_SET_COMPLETIONS:
|
case actions.CONSOLE_SET_COMPLETIONS:
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
|
|
|
@ -40,7 +40,7 @@ const reloadSettings = () => {
|
||||||
|
|
||||||
browser.runtime.onMessage.addListener((action) => {
|
browser.runtime.onMessage.addListener((action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case messages.CONSOLE_HIDE:
|
case messages.CONSOLE_HIDE_COMMAND:
|
||||||
window.focus();
|
window.focus();
|
||||||
consoleFrames.blur(window.document);
|
consoleFrames.blur(window.document);
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
|
|
|
@ -8,7 +8,7 @@ export default {
|
||||||
CONSOLE_QUERY_COMPLETIONS: 'console.query.completions',
|
CONSOLE_QUERY_COMPLETIONS: 'console.query.completions',
|
||||||
CONSOLE_SHOW_COMMAND: 'console.show.command',
|
CONSOLE_SHOW_COMMAND: 'console.show.command',
|
||||||
CONSOLE_SHOW_ERROR: 'console.show.error',
|
CONSOLE_SHOW_ERROR: 'console.show.error',
|
||||||
CONSOLE_HIDE: 'console.hide',
|
CONSOLE_HIDE_COMMAND: 'console.hide.command',
|
||||||
|
|
||||||
OPEN_URL: 'open.url',
|
OPEN_URL: 'open.url',
|
||||||
|
|
||||||
|
|
|
@ -20,9 +20,9 @@ describe("console actions", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("hide", () => {
|
describe("hide", () => {
|
||||||
it('create CONSOLE_HIDE action', () => {
|
it('create CONSOLE_HIDE_COMMAND action', () => {
|
||||||
let action = consoleActions.hide();
|
let action = consoleActions.hideCommand();
|
||||||
expect(action.type).to.equal(actions.CONSOLE_HIDE);
|
expect(action.type).to.equal(actions.CONSOLE_HIDE_COMMAND);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,8 @@ import reducer from 'console/reducers';
|
||||||
describe("console reducer", () => {
|
describe("console reducer", () => {
|
||||||
it('return the initial state', () => {
|
it('return the initial state', () => {
|
||||||
let state = reducer(undefined, {});
|
let state = reducer(undefined, {});
|
||||||
expect(state).to.have.property('errorShown', false);
|
expect(state).to.have.property('mode', '');
|
||||||
expect(state).to.have.property('errorText', '');
|
expect(state).to.have.property('messageText', '');
|
||||||
expect(state).to.have.property('commandShown', false);
|
|
||||||
expect(state).to.have.property('commandText', '');
|
expect(state).to.have.property('commandText', '');
|
||||||
expect(state).to.have.deep.property('completions', []);
|
expect(state).to.have.deep.property('completions', []);
|
||||||
expect(state).to.have.property('groupSelection', -1);
|
expect(state).to.have.property('groupSelection', -1);
|
||||||
|
@ -17,24 +16,24 @@ describe("console reducer", () => {
|
||||||
it('return next state for CONSOLE_SHOW_COMMAND', () => {
|
it('return next state for CONSOLE_SHOW_COMMAND', () => {
|
||||||
let action = { type: actions.CONSOLE_SHOW_COMMAND, text: 'open ' };
|
let action = { type: actions.CONSOLE_SHOW_COMMAND, text: 'open ' };
|
||||||
let state = reducer({}, action);
|
let state = reducer({}, action);
|
||||||
expect(state).to.have.property('commandShown', true);
|
expect(state).to.have.property('mode', 'command');
|
||||||
expect(state).to.have.property('commandText', 'open ');
|
expect(state).to.have.property('commandText', 'open ');
|
||||||
expect(state).to.have.property('errorShown', false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('return next state for CONSOLE_SHOW_ERROR', () => {
|
it('return next state for CONSOLE_SHOW_ERROR', () => {
|
||||||
let action = { type: actions.CONSOLE_SHOW_ERROR, text: 'an error' };
|
let action = { type: actions.CONSOLE_SHOW_ERROR, text: 'an error' };
|
||||||
let state = reducer({}, action);
|
let state = reducer({}, action);
|
||||||
expect(state).to.have.property('errorShown', true);
|
expect(state).to.have.property('mode', 'error');
|
||||||
expect(state).to.have.property('errorText', 'an error');
|
expect(state).to.have.property('messageText', 'an error');
|
||||||
expect(state).to.have.property('commandShown', false);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('return next state for CONSOLE_HIDE', () => {
|
it('return next state for CONSOLE_HIDE_COMMAND', () => {
|
||||||
let action = { type: actions.CONSOLE_HIDE };
|
let action = { type: actions.CONSOLE_HIDE_COMMAND };
|
||||||
let state = reducer({}, action);
|
let state = reducer({ mode: 'command' }, action);
|
||||||
expect(state).to.have.property('errorShown', false);
|
expect(state).to.have.property('mode', '');
|
||||||
expect(state).to.have.property('commandShown', false);
|
|
||||||
|
state = reducer({ mode: 'error' }, action);
|
||||||
|
expect(state).to.have.property('mode', 'error');
|
||||||
});
|
});
|
||||||
|
|
||||||
it ('return next state for CONSOLE_SET_COMPLETIONS', () => {
|
it ('return next state for CONSOLE_SET_COMPLETIONS', () => {
|
||||||
|
|
Reference in a new issue