2018-01-03 02:12:57 +01:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
|
|
|
import Dropzone from './components/dropzone.jsx';
|
|
|
|
import PublishDetails from './components/publishDetails.jsx';
|
|
|
|
import PublishStatus from './components/publishStatus.jsx';
|
|
|
|
|
|
|
|
const DROPZONE = 'DROPZONE';
|
|
|
|
const DETAILS = 'DETAILS';
|
|
|
|
const STATUS = 'STATUS';
|
2018-01-04 19:39:51 +01:00
|
|
|
const initialState = {
|
|
|
|
showComponent: DROPZONE, // DROPZONE, DETAILS, or PUBLISHING
|
|
|
|
file : null,
|
|
|
|
title : '',
|
|
|
|
channel : '',
|
|
|
|
url : '',
|
|
|
|
thumbnail : '',
|
|
|
|
description : '',
|
|
|
|
license : '',
|
|
|
|
nsfw : '',
|
|
|
|
}
|
2018-01-03 02:12:57 +01:00
|
|
|
|
|
|
|
class Uploader extends React.Component {
|
|
|
|
constructor (props) {
|
|
|
|
super(props);
|
2018-01-04 19:39:51 +01:00
|
|
|
this.state = initialState;
|
2018-01-03 02:12:57 +01:00
|
|
|
// bind class methods with `this`
|
|
|
|
this.updateUploaderState = this.updateUploaderState.bind(this);
|
2018-01-04 19:39:51 +01:00
|
|
|
this.clearUploaderState = this.clearUploaderState.bind(this);
|
2018-01-03 02:12:57 +01:00
|
|
|
this.showComponent = this.showComponent.bind(this);
|
|
|
|
this.stageFileAndShowDetails = this.stageFileAndShowDetails.bind(this);
|
|
|
|
}
|
|
|
|
updateUploaderState (name, value) {
|
|
|
|
console.log(`updateUploaderState ${name} ${value}`);
|
|
|
|
this.setState({[name]: value});
|
|
|
|
}
|
2018-01-04 19:39:51 +01:00
|
|
|
clearUploaderState () {
|
|
|
|
this.setState(initialState);
|
|
|
|
}
|
2018-01-03 02:12:57 +01:00
|
|
|
showComponent (component) {
|
|
|
|
this.setState({showComponent: component});
|
|
|
|
}
|
|
|
|
stageFileAndShowDetails (selectedFile) {
|
|
|
|
console.log('stageFileAndShowDetails', selectedFile);
|
|
|
|
// store the selected file for upload
|
|
|
|
this.setState({'file': selectedFile});
|
|
|
|
// hide the dropzone and show the details
|
|
|
|
this.showComponent(DETAILS);
|
|
|
|
}
|
|
|
|
render () {
|
|
|
|
return (
|
2018-01-04 20:05:16 +01:00
|
|
|
<div className="row row--tall">
|
2018-01-03 02:12:57 +01:00
|
|
|
{ this.state.showComponent === DROPZONE &&
|
|
|
|
<Dropzone stageFileAndShowDetails={this.stageFileAndShowDetails}/>
|
|
|
|
}
|
|
|
|
{ this.state.showComponent === DETAILS &&
|
|
|
|
<PublishDetails
|
|
|
|
updateUploaderState={this.updateUploaderState}
|
2018-01-04 19:39:51 +01:00
|
|
|
clearUploaderState={this.clearUploaderState}
|
2018-01-03 02:12:57 +01:00
|
|
|
file={this.state.file}
|
|
|
|
title={this.state.title}
|
|
|
|
channel={this.state.channel}
|
|
|
|
url={this.state.url}
|
|
|
|
thumbnail={this.state.thumbnail}
|
|
|
|
description={this.state.description}
|
|
|
|
license={this.state.license}
|
|
|
|
nsfw={this.state.nsfw}
|
|
|
|
/>
|
|
|
|
}
|
|
|
|
{ this.state.showComponent === STATUS &&
|
|
|
|
<PublishStatus />
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ReactDOM.render(
|
|
|
|
<Uploader />,
|
|
|
|
document.getElementById('react-uploader')
|
|
|
|
);
|