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

const bigganInitialState = {
  loading: true,
  progress: { i: 0, n: 0 },
  error: null,
  folder_id: 0,
  data: null,
  results: null,
  encodings: null,
  checkpoint: {
    name: '',
    sequenceCount: 0,
    datasetCount: 0,
  }
}

const bigganReducer = (state = bigganInitialState, action) => {
  if (action.data && action.data.module === 'biggan') {
    state = datasetReducer(state, action)
  }

  switch (action.type) {
    case types.biggan.load_results:
      return {
        ...state,
        results: action.results,
      }
    case types.biggan.load_encodings:
      return {
        ...state,
        encodings: action.encodings,
      }
    case types.file.destroy:
      console.log('file destroy', state.results)
      return {
        ...state,
        results: {
          ...state.results,
          files: state.results.files.filter(f => f.id !== action.data.id)
        }
      }
    default:
      return state
  }
}

export default bigganReducer