summaryrefslogtreecommitdiff
path: root/app/client/modules/samplernn/samplernn.import.js
blob: 6736d4b454c18b0ccbd0616993adc0d50fac097b (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import { h, Component } from 'preact'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import * as util from '../../util'

import * as samplernnActions from './samplernn.actions'

import Select from '../../common/select.component'
import TextInput from '../../common/textInput.component'
import Button from '../../common/button.component'

import SampleRNNDatasets from './samplernn.datasets'

const samplernnModule = {
  name: 'samplernn',
  datatype: 'audio',
}

class SampleRNNImport extends Component {
  constructor(){
    super()
    this.state = {
      folder: 1,
      import_action: 'Hotlink',
      url_base: 'https://s3.amazonaws.com/i.asdf.us/bucky/data/4279/',
      selected: {},
    }
  }
  render(){
    let datasets = [];
    if (this.props.samplernn.data) {
      datasets = (this.props.samplernn.data.folders || []).map(folder => {
        return [folder.name, folder.id]
      })
    }
    return (
      <div className='app top'>
        <div class='heading'>
          <h1>Import</h1>
        </div>
        <div class='params form row datasets'>
          <div class='row dataset'>
            <div class='col'>
            </div>
            <div class='col'>
            </div>
            <div class='col'>
            </div>
            <div class='col'>
              <h2>Import to dataset</h2>
              <Select
                title='Destination dataset'
                options={datasets}
                name='folder'
                opt={this.state}
                onChange={(name, value) => this.setState({ folder: value })}
              />
              <Select
                title='Import action'
                options={['Hotlink', 'Upload']}
                name='import_action'
                opt={this.state}
                onChange={(name, value) => this.setState({ import_action: value })}
              />
              <TextInput
                title="Remote URL base"
                value={this.state.url_base}
                placeholder="http://"
                onSave={(value) => this.setState({ url_base: value })}
              />
              <Button
                title=""
                onClick={() => this.doImport()}
              >
                Import
              </Button>
            </div>
          </div>
        </div>
        <SampleRNNDatasets
          id="unsorted"
          history={this.props.history}
          onPickDataset={(dataset => this.toggle(dataset.name, this.state.selected[name]))}
          beforeRow={dataset => this.beforeRow(dataset)}
          afterRow={dataset => this.afterRow(dataset)}
        />
      </div>
    )
  }
  toggle(name){
    this.setState({
      ...this.state,
      selected: {
        ...this.state.selected,
        [name]: !this.state.selected[name],
      }
    })
  }
  beforeRow(dataset){
    // console.log(dataset)
  }
  afterRow(dataset){
    const name = dataset.name
    return (
      <div>
        <input
          type="checkbox"
          value={name}
          checked={!!this.state.selected[name]}
        />
      </div>
    )
  }
  doImport(){
    const { samplernn } = this.props
    console.log(this.state)
    this.props.actions.import_files(this.state, samplernn.data.datasetLookup)
  }
}

const mapStateToProps = state => ({
  samplernn: state.module.samplernn,
  runner: state.system.runner,
  task: state.task,
})

const mapDispatchToProps = (dispatch, ownProps) => ({
  actions: bindActionCreators(samplernnActions, dispatch),
})

export default connect(mapStateToProps, mapDispatchToProps)(SampleRNNImport)