diff options
| author | Matthew Shao <me@matshao.com> | 2017-07-17 15:32:52 +0800 |
|---|---|---|
| committer | Matthew Shao <me@matshao.com> | 2017-07-17 15:32:52 +0800 |
| commit | 4a02822b346c3aed361c77bb714903a59ac6935e (patch) | |
| tree | 75f788ab0eb58b0b1f0785a92b96044f49fc3627 /web/src/js/ducks | |
| parent | c19a184ba2e0327a8df0c2a4631f81f4f40e939b (diff) | |
| download | mitmproxy-4a02822b346c3aed361c77bb714903a59ac6935e.tar.gz mitmproxy-4a02822b346c3aed361c77bb714903a59ac6935e.tar.bz2 mitmproxy-4a02822b346c3aed361c77bb714903a59ac6935e.zip | |
[web] Update OptionMaster.
Diffstat (limited to 'web/src/js/ducks')
| -rw-r--r-- | web/src/js/ducks/options.js | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/web/src/js/ducks/options.js b/web/src/js/ducks/options.js index ed82d7f3..48e3708b 100644 --- a/web/src/js/ducks/options.js +++ b/web/src/js/ducks/options.js @@ -1,10 +1,10 @@ import { fetchApi } from '../utils' +import * as optionActions from './ui/option' export const RECEIVE = 'OPTIONS_RECEIVE' export const UPDATE = 'OPTIONS_UPDATE' export const REQUEST_UPDATE = 'REQUEST_UPDATE' export const UNKNOWN_CMD = 'OPTIONS_UNKNOWN_CMD' -export const ERROR = 'OPTIONS_ERROR' const defaultState = { @@ -22,26 +22,23 @@ export default function reducer(state = defaultState, action) { ...action.data, } - case ERROR: - return { - ...state, - ...action.data, - } - default: return state } } export function update(options) { - let error = '' - fetchApi.put('/options', options).then( - (response) => { - response.text().then(errorMsg => { - error = errorMsg - console.log(error) - }) - } - ) - return {type: ERROR, error} + return dispatch => { + let option = Object.keys(options)[0] + dispatch({ type: optionActions.OPTION_UPDATE_START, option, value: options[option] }) + fetchApi.put('/options', options).then(response => { + if (response.status === 200) { + dispatch({ type: optionActions.OPTION_UPDATE_SUCCESS, option}) + } else { + response.text().then( text => { + dispatch({type: optionActions.OPTION_UPDATE_ERROR, error: text, option}) + }) + } + }) + } } |
