summaryrefslogtreecommitdiff
path: root/app/client/dashboard/dashboard.component.js
blob: cbfdd334a1783fb1e927eed8cde07da5f53657c8 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import { h, Component } from 'preact'
import { bindActionCreators } from 'redux'
import { Link } from 'react-router-dom'
import { connect } from 'react-redux'

import Player from '../common/player.component'
import Group from '../common/group.component'
import Slider from '../common/slider.component'
import Select from '../common/select.component'
import Button from '../common/button.component'

import DashboardHeader from './dashboardheader.component'
import { Loading, FolderList, FileList, TaskList, Gallery } from '../common'

import * as dashboardActions from './dashboard.actions'
import * as audioPlayerActions from '../common/audioPlayer/audioPlayer.actions'
import modules from '../modules'
import actions from '../actions'

class Dashboard extends Component {
  constructor(props){
    super()
    // console.log(props)
    props.actions.load()
  }
  componentWillUpdate(nextProps) {
    // if (nextProps.opt.checkpoint_name && nextProps.opt.checkpoint_name !== this.props.opt.checkpoint_name) {
    //   this.props.actions.list_epochs(nextProps.opt.checkpoint_name)
  }
  render(){
    const { loading, progress, site, foldersByModule, renders, queue, images } = this.props
    if (loading) {
      return <Loading progress={progress} />
    }
    const { tasks } = queue
    const folders = foldersByModule && Object.keys(modules).sort().map(key => {
      let path = key === 'samplernn' ? '/samplernn/datasets/' : '/' + key + '/sequences/'
      let folder_list = (foldersByModule[key] || []).map(folder => {
        return (
          <div key={folder.id}>
            <Link to={path + folder.id + '/'}>{folder.name}</Link>
          </div>
        )
      })

      let files = renders[key] && (
        <FileList
          linkFiles
          files={renders[key]}
          orderBy='date desc'
          fields={'name date epoch size'}
          onClick={key === 'samplernn' ? (file, e) => {
            e.preventDefault()
            e.stopPropagation()
            console.log('picked a file', file)
            this.handlePick(file)
          } : null}
        />
      );

      return (
        <div className='dashboardModule' key={key}>
          <div className='row moduleHeading'>
            <h3>{key}</h3>
            <div>
              <Link to={'/' + key + '/new/'}>new</Link>
            </div>
            {folder_list}
          </div>
          {files}
        </div>
      )
    }).filter(a => !!a)
    return (
      <div className='app dashboard'>
        <DashboardHeader />
        <div className='params row'>
          <div className='column'>
            {!!queue.queue.length &&
              <Group title='Upcoming Tasks'>
                <TaskList tasks={queue.queue.map(id => tasks[id])} />
              </Group>
            }
            {!!queue.completed.length &&
              <Group title='Completed Tasks'>
                <TaskList tasks={queue.completed.map(id => tasks[id])} />
              </Group>
            }
          </div>
          <div className='column'>
            {folders}
          </div>
        </div>
      </div>
    )
  }
  handlePick(file){
    this.props.audioPlayer.play(file)
  }
}
const mapStateToProps = state => ({
  loading: state.dashboard.loading,
  progress: state.dashboard.progress,
  site: state.system.site,
  foldersByModule: state.dashboard.data.foldersByModule,
  renders: state.dashboard.data.renders,
  images: state.dashboard.images,
  files: state.dashboard.files,
  queue: state.queue,
})

const mapDispatchToProps = (dispatch, ownProps) => ({
  actions: bindActionCreators(dashboardActions, dispatch),
  audioPlayer: bindActionCreators(audioPlayerActions, dispatch),
})

export default connect(mapStateToProps, mapDispatchToProps)(Dashboard)