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 DatasetForm from '../../dataset/dataset.form' import NewDatasetForm from '../../dataset/dataset.new' import { FileList, FileRow } from '../../common/fileList.component' const samplernnModule = { name: 'samplernn', datatype: 'audio', } class SampleRNNDatasets extends Component { constructor(props){ super(props) console.log('ba') this.fileOptions = this.fileOptions.bind(this) this.pickFile = this.pickFile.bind(this) } componentWillMount(){ const id = this.props.id || this.props.match.params.id || localStorage.getItem('samplernn.last_id') console.log(id) console.log('load dataset:', id) const { match, samplernn, actions } = this.props if (id === 'new') return if (id) { localStorage.setItem('samplernn.last_id', id) if (! samplernn.folder || samplernn.folder.id !== id) { console.log('load directories') actions.load_directories(id) } } } pickFile(file){ console.log('pick', file) } fileOptions(file){ if (file.activity === 'url' && !file.dataset) { if (this.props.runner.cpu.status !== 'IDLE') { return (
fetching...
) } else { return (
this.fetchURL(file.url)}> fetch
) } } return (
this.train(file)}>train
{file.epoch == 0 &&
{file.epochs} ep.
}
) } render(){ const { samplernn, match, history } = this.props const id = this.props.id || localStorage.getItem('samplernn.last_id') console.log(this.props.id) if (this.props.id && this.props.id !== 'new') return null if (samplernn.loading) { console.log('loading') return Loading } if (!samplernn.folder || !samplernn.data.folders.length) { console.log('no folders, redirect to /new') return history.push('/samplernn/new/') } console.log('render app') const folder = samplernn.folder console.log(folder) if (!folder || !folder.name) return console.log(folder.name) return (

{folder.name}

{folder.name !== 'unsorted' && } {this.renderDataset()}
) } renderDataset(){ return (
input
checkpoint
output
{this.renderGroups()}
) } renderGroups(){ const { samplernn } = this.props const folder = samplernn.folder const { mapFn, sortFn } = util.sort.orderByFn('date desc') const datasets = folder.datasets.map(mapFn).sort(sortFn).map(pair => { const dataset = pair[1] return (
{this.props.beforeRow && this.props.beforeRow(dataset)}
{!!dataset.input.length && }
{dataset.isBuilt ? 'cached' : ''}
{!!dataset.checkpoints.length && }
{!!dataset.output.length && }
) }) return datasets } } 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)(SampleRNNDatasets)