import * as types from 'app/types' // import { session, getDefault, getDefaultInt } from 'app/session' import { crudState, crudReducer } from 'app/api/crud.reducer' const resetEditor = { addingPage: false, editingPage: false, showingAudio: false, showingCursors: false, } const initialState = crudState('graph', { editor: { ...resetEditor, building: 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.upload.upload_complete: console.log(action) return { ...state, show: { ...state.show, res: { ...state.show.res, uploads: state.show.res.uploads.concat(action.data.res) } } } case types.graph.show_add_page_form: return { ...state, editor: { ...state.editor, ...resetEditor, addingPage: true, } } case types.graph.hide_add_page_form: return { ...state, editor: { ...state.editor, ...resetEditor, } } case types.graph.toggle_add_page_form: return { ...state, editor: { ...state.editor, ...resetEditor, addingPage: !state.editor.addingPage, } } case types.graph.show_edit_page_form: return { ...state, editor: { ...state.editor, ...resetEditor, editingPage: true, } } case types.graph.hide_edit_page_form: return { ...state, editor: { ...state.editor, ...resetEditor, } } case types.graph.toggle_edit_page_form: return { ...state, editor: { ...state.editor, ...resetEditor, editingPage: !state.editor.editingPage, } } case types.graph.toggle_audio_list: return { ...state, editor: { ...state.editor, ...resetEditor, showingAudio: !state.editor.showingAudio, } } case types.graph.toggle_cursor_list: return { ...state, editor: { ...state.editor, ...resetEditor, showingCursors: !state.editor.showingCursors, } } case types.api.loading: if (action.tag !== 'view' && action.tag !== 'export') { return state } return { ...state, editor: { ...state.editor, building: action.tag } } case types.api.loaded: case types.api.error: if (action.tag !== 'view' && action.tag !== 'export') { return state } return { ...state, editor: { ...state.editor, building: null } } default: return state } }