mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-25 18:03:50 +00:00
[web] Add reducer and actions for option editor.
This commit is contained in:
parent
6be1c2efb9
commit
ec5061327f
@ -2,10 +2,12 @@ import { combineReducers } from 'redux'
|
|||||||
import flow from './flow'
|
import flow from './flow'
|
||||||
import header from './header'
|
import header from './header'
|
||||||
import modal from './modal'
|
import modal from './modal'
|
||||||
|
import option from './option'
|
||||||
|
|
||||||
// TODO: Just move ducks/ui/* into ducks/?
|
// TODO: Just move ducks/ui/* into ducks/?
|
||||||
export default combineReducers({
|
export default combineReducers({
|
||||||
flow,
|
flow,
|
||||||
header,
|
header,
|
||||||
modal
|
modal,
|
||||||
|
option,
|
||||||
})
|
})
|
||||||
|
39
web/src/js/ducks/ui/option.js
Normal file
39
web/src/js/ducks/ui/option.js
Normal file
@ -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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user