From babd967eb8ac62c4a6ff6734ff57e46faaa5bab6 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Mon, 17 Jul 2017 20:46:28 +0200 Subject: [web] options: make help and err permanently visible, improve perf --- web/src/js/ducks/ui/optionsEditor.js | 73 ++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 web/src/js/ducks/ui/optionsEditor.js (limited to 'web/src/js/ducks/ui/optionsEditor.js') diff --git a/web/src/js/ducks/ui/optionsEditor.js b/web/src/js/ducks/ui/optionsEditor.js new file mode 100644 index 00000000..23dfe01a --- /dev/null +++ b/web/src/js/ducks/ui/optionsEditor.js @@ -0,0 +1,73 @@ +import { HIDE_MODAL } from "./modal" + +export const OPTION_UPDATE_START = 'UI_OPTION_UPDATE_START' +export const OPTION_UPDATE_SUCCESS = 'UI_OPTION_UPDATE_SUCCESS' +export const OPTION_UPDATE_ERROR = 'UI_OPTION_UPDATE_ERROR' + +const defaultState = { + /* optionName -> {isUpdating, value (client-side), error} */ +} + +export default function reducer(state = defaultState, action) { + switch (action.type) { + case OPTION_UPDATE_START: + return { + ...state, + [action.option]: { + isUpdate: true, + value: action.value, + error: false, + } + } + + case OPTION_UPDATE_SUCCESS: + return { + ...state, + [action.option]: undefined + } + + case OPTION_UPDATE_ERROR: + let val = state[action.option].value; + if (typeof(val) === "boolean") { + // If a boolean option errs, reset it to its previous state to be less confusing. + // Example: Start mitmweb, check "add_upstream_certs_to_client_chain". + val = !val; + } + return { + ...state, + [action.option]: { + value: val, + isUpdating: false, + error: action.error + } + } + + case HIDE_MODAL: + return {} + + default: + return state + } +} + +export function startUpdate(option, value) { + return { + type: OPTION_UPDATE_START, + option, + value, + } +} +export function updateSuccess(option) { + return { + type: OPTION_UPDATE_SUCCESS, + option, + } +} + +export function updateError(option, error) { + return { + type: OPTION_UPDATE_ERROR, + option, + error, + } +} -- cgit v1.2.3 From f465f08c9ac302007b3aec6709a8e82d63c7ad65 Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Thu, 20 Jul 2017 15:39:43 +0800 Subject: [web] Minor fix and update tests. --- web/src/js/ducks/ui/optionsEditor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'web/src/js/ducks/ui/optionsEditor.js') diff --git a/web/src/js/ducks/ui/optionsEditor.js b/web/src/js/ducks/ui/optionsEditor.js index 23dfe01a..a8a8f69e 100644 --- a/web/src/js/ducks/ui/optionsEditor.js +++ b/web/src/js/ducks/ui/optionsEditor.js @@ -14,7 +14,7 @@ export default function reducer(state = defaultState, action) { return { ...state, [action.option]: { - isUpdate: true, + isUpdating: true, value: action.value, error: false, } -- cgit v1.2.3