summaryrefslogtreecommitdiff
path: root/app/client/dashboard/dashboard.actions.js
blob: 7a6aa1dca412ae92e51c1e47107da4daa7c6f6da (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
import types from '../types'
import actions from '../actions'
import util from '../util'

export const load = () => (dispatch) => {
  util.allProgress([
    actions.task.index({ limit: 40, orderBy: 'created_at desc', }),
    actions.folder.index(),
    actions.file.index({ module: 'samplernn', generated: 1, limit: 10, orderBy: 'created_at desc', })
  ], (percent, i, n) => {
    console.log('dashboard load progress', i, n)
    dispatch({ type: types.app.load_progress, progress: { i, n }})
  }).then(res => {
    const [ tasks, folders, sampleRNNrenders ] = res
    const { mapFn, sortFn } = util.sort.orderByFn('date desc')
    const foldersByModule = folders.map(mapFn).sort(sortFn).reduce((a,b) => {
      const module = b[1].module
      a[module] = a[module] || []
      a[module].push(b[1])
      return a
    }, {})
    dispatch({
      type: types.dashboard.load,
      data: {
        tasks,
        folders,
        sampleRNNrenders,
        foldersByModule,
      },
    })

  })
}