summaryrefslogtreecommitdiff
path: root/app/client/modules/morph/morph.reducer.js
blob: 5c46a4effd7d383227a9e5949c27b0d147f5cc34 (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
import types from '../../types'
import datasetReducer from '../../dataset/dataset.reducer'

const morphInitialState = {
  loading: true,
  progress: { i: 0, n: 0 },
  error: null,
  folder_id: 0,
  data: null,
  app: null,
}

const morphReducer = (state = morphInitialState, action) => {
  if (action.data && action.data.module === 'morph') {
    state = datasetReducer(state, action)
  }

  switch (action.type) {
    case types.morph.load:
      console.log('morph load', action.app)
      return {
        ...state,
        app: action.app,
        loading: false,
        data: action.data,
      }
    case types.file.create:
      console.log(action)
      if (action.data.module !== 'morph') return state
      return {
        ...state,
        app: state.app && {
          ...state.app,
          files: [action.data].concat(state.app.files)
        }
      }
    default:
      return state
  }
}

export default morphReducer