summaryrefslogtreecommitdiff
path: root/frontend/views/page/page.reducer.js
blob: d1d6510b6dbc818faf5af5811ced0efcfc8e1f20 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import * as types from '../../types'
// import { session, getDefault, getDefaultInt } from '../../session'

import { crudState, crudReducer } from '../../api/crud.reducer'

const initialState = crudState('page', {
  editor: {
    addingTile: false,
    editingTile: false,
  },
  options: {
  }
})

const reducer = crudReducer('page')

export default function pageReducer(state = initialState, action) {
  console.log(action.type, action)
  state = reducer(state, action)
  switch (action.type) {
    case types.page.update_page_tile:
      return {
        ...state,
        show: {
          ...state.show,
          res: {
            ...state.show.res,
            tiles: state.show.res.tiles.map(tile => {
              if (tile.id === action.tile.id) {
                return { ...action.tile }
              } else {
                return tile
              }
            }),
          }
        }
      }

    case types.page.show_add_tile_form:
      return {
        ...state,
        editor: {
          ...state.editor,
          addingTile: true,
        }
      }

    case types.page.hide_add_tile_form:
      return {
        ...state,
        editor: {
          ...state.editor,
          addingTile: false,
        }
      }

    case types.page.show_edit_tile_form:
      return {
        ...state,
        editor: {
          ...state.editor,
          addingTile: true,
        }
      }

    case types.page.hide_edit_tile_form:
      return {
        ...state,
        editor: {
          ...state.editor,
          addingTile: false,
        }
      }

    default:
      return state
  }
}