diff options
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}) + }) + } + }) + } } |