From c05a918de5f52b0333da4ab3e96b0a76611fe101 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Sun, 3 Jun 2018 19:53:33 +0200 Subject: abstract this ugly datasets code!! --- app/client/modules/samplernn/samplernn.datasets.js | 33 +++++++++++++++------- 1 file changed, 23 insertions(+), 10 deletions(-) (limited to 'app/client/modules/samplernn/samplernn.datasets.js') diff --git a/app/client/modules/samplernn/samplernn.datasets.js b/app/client/modules/samplernn/samplernn.datasets.js index 2a8c224..d37102b 100644 --- a/app/client/modules/samplernn/samplernn.datasets.js +++ b/app/client/modules/samplernn/samplernn.datasets.js @@ -16,17 +16,22 @@ const samplernnModule = { class SampleRNNDatasets extends Component { constructor(props){ - super() + super(props) + console.log('ba') this.fileOptions = this.fileOptions.bind(this) this.pickFile = this.pickFile.bind(this) - let id = props.match.params.id || localStorage.getItem('samplernn.last_id') + } + 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 (! props.samplernn.folder || props.samplernn.folder.id !== id) { + if (! samplernn.folder || samplernn.folder.id !== id) { console.log('load directories') - props.actions.load_directories(id) + actions.load_directories(id) } } } @@ -58,16 +63,22 @@ class SampleRNNDatasets extends Component { } render(){ const { samplernn, match, history } = this.props - const folder = samplernn.folder - if (match.params.id === 'new') { - return - } + 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 (!folder || !samplernn.data.folders.length) { - return history.push('/samplernn/datasets/new/') + 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 (
@@ -106,6 +117,7 @@ class SampleRNNDatasets extends Component { const dataset = pair[1] return (
+ {this.props.beforeRow && this.props.beforeRow(dataset)}
{!!dataset.input.length && }
-- cgit v1.2.3-70-g09d2