diff options
| author | Maximilian Hils <git@maximilianhils.com> | 2017-07-20 18:01:53 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-07-20 18:01:53 +0200 |
| commit | e1d0bc6de975c377cb42022209ea1b5bce515433 (patch) | |
| tree | 4f52c967b9312dd0c08e3f88f51b93dd2849dffe /web/src/js/ducks/ui/optionsEditor.js | |
| parent | 8526ca9e175af4a903348c39928535ae10f7543d (diff) | |
| parent | cb73658dd43e01bdedd84aa31601887b19c106ca (diff) | |
| download | mitmproxy-e1d0bc6de975c377cb42022209ea1b5bce515433.tar.gz mitmproxy-e1d0bc6de975c377cb42022209ea1b5bce515433.tar.bz2 mitmproxy-e1d0bc6de975c377cb42022209ea1b5bce515433.zip | |
Merge pull request #2430 from MatthewShao/mitmweb-options
[web] [WIP] Mitmweb options
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..a8a8f69e --- /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]: { + isUpdating: 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, + } +} |
