diff options
Diffstat (limited to 'frontend/views/graph/graph.reducer.js')
| -rw-r--r-- | frontend/views/graph/graph.reducer.js | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/frontend/views/graph/graph.reducer.js b/frontend/views/graph/graph.reducer.js new file mode 100644 index 0000000..9e682e4 --- /dev/null +++ b/frontend/views/graph/graph.reducer.js @@ -0,0 +1,78 @@ +import * as types from '../../types' +// import { session, getDefault, getDefaultInt } from '../../session' + +import { crudState, crudReducer } from '../../api/crud.reducer' + +const initialState = crudState('graph', { + editor: { + addingPage: false, + editingPage: false, + }, + options: { + } +}) + +const reducer = crudReducer('graph') + +export default function graphReducer(state = initialState, action) { + // console.log(action.type, action) + state = reducer(state, action) + switch (action.type) { + case types.graph.update_graph_page: + return { + ...state, + show: { + ...state.show, + res: { + ...state.show.res, + pages: state.show.res.pages.map(page => { + if (page.id === action.page.id) { + return { ...action.page } + } else { + return page + } + }), + } + } + } + + case types.graph.show_add_page_form: + return { + ...state, + editor: { + ...state.editor, + addingPage: true, + } + } + + case types.graph.hide_add_page_form: + return { + ...state, + editor: { + ...state.editor, + addingPage: false, + } + } + + case types.graph.show_edit_page_form: + return { + ...state, + editor: { + ...state.editor, + addingPage: true, + } + } + + case types.graph.hide_edit_page_form: + return { + ...state, + editor: { + ...state.editor, + addingPage: false, + } + } + + default: + return state + } +} |
