diff options
Diffstat (limited to 'web/src/js/ducks')
-rw-r--r-- | web/src/js/ducks/options.js | 1 | ||||
-rw-r--r-- | web/src/js/ducks/ui/option.js | 39 |
2 files changed, 39 insertions, 1 deletions
diff --git a/web/src/js/ducks/options.js b/web/src/js/ducks/options.js index 286a1ae3..3277fb9e 100644 --- a/web/src/js/ducks/options.js +++ b/web/src/js/ducks/options.js @@ -25,7 +25,6 @@ export default function reducer(state = defaultState, action) { } } - let sendUpdate = (option, value, dispatch) => { fetchApi.put('/options', { [option]: value }).then(response => { if (response.status === 200) { diff --git a/web/src/js/ducks/ui/option.js b/web/src/js/ducks/ui/option.js new file mode 100644 index 00000000..6aba4998 --- /dev/null +++ b/web/src/js/ducks/ui/option.js @@ -0,0 +1,39 @@ +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: + let s = {...state} + delete s[action.option] + return s + + case OPTION_UPDATE_ERROR: + return { + ...state, + [action.option]: { + ...state[action.option], + isUpdating: false, + error: action.error + } + } + + default: + return state + } +} |