diff options
author | Maximilian Hils <git@maximilianhils.com> | 2017-07-17 20:46:28 +0200 |
---|---|---|
committer | Maximilian Hils <git@maximilianhils.com> | 2017-07-17 21:04:01 +0200 |
commit | babd967eb8ac62c4a6ff6734ff57e46faaa5bab6 (patch) | |
tree | c44148fd3fc96f94f76442d1c8bcb97e117e169b /web/src/js/ducks/ui/optionsEditor.js | |
parent | 21b3f9c02956c625c576c6787ab10409aab0618d (diff) | |
download | mitmproxy-babd967eb8ac62c4a6ff6734ff57e46faaa5bab6.tar.gz mitmproxy-babd967eb8ac62c4a6ff6734ff57e46faaa5bab6.tar.bz2 mitmproxy-babd967eb8ac62c4a6ff6734ff57e46faaa5bab6.zip |
[web] options: make help and err permanently visible, improve perf
Diffstat (limited to 'web/src/js/ducks/ui/optionsEditor.js')
-rw-r--r-- | web/src/js/ducks/ui/optionsEditor.js | 73 |
1 files changed, 73 insertions, 0 deletions
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, + } +} |