React/Redux - publish component #323
4 changed files with 77 additions and 31 deletions
|
@ -975,16 +975,7 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
|
||||||
var DROPZONE = 'DROPZONE';
|
var DROPZONE = 'DROPZONE';
|
||||||
var DETAILS = 'DETAILS';
|
var DETAILS = 'DETAILS';
|
||||||
var STATUS = 'STATUS';
|
var STATUS = 'STATUS';
|
||||||
|
var initialState = {
|
||||||
var Uploader = function (_React$Component) {
|
|
||||||
_inherits(Uploader, _React$Component);
|
|
||||||
|
|
||||||
function Uploader(props) {
|
|
||||||
_classCallCheck(this, Uploader);
|
|
||||||
|
|
||||||
var _this = _possibleConstructorReturn(this, (Uploader.__proto__ || Object.getPrototypeOf(Uploader)).call(this, props));
|
|
||||||
|
|
||||||
_this.state = {
|
|
||||||
showComponent: DROPZONE, // DROPZONE, DETAILS, or PUBLISHING
|
showComponent: DROPZONE, // DROPZONE, DETAILS, or PUBLISHING
|
||||||
file: null,
|
file: null,
|
||||||
title: '',
|
title: '',
|
||||||
|
@ -994,9 +985,20 @@ var Uploader = function (_React$Component) {
|
||||||
description: '',
|
description: '',
|
||||||
license: '',
|
license: '',
|
||||||
nsfw: ''
|
nsfw: ''
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var Uploader = function (_React$Component) {
|
||||||
|
_inherits(Uploader, _React$Component);
|
||||||
|
|
||||||
|
function Uploader(props) {
|
||||||
|
_classCallCheck(this, Uploader);
|
||||||
|
|
||||||
|
var _this = _possibleConstructorReturn(this, (Uploader.__proto__ || Object.getPrototypeOf(Uploader)).call(this, props));
|
||||||
|
|
||||||
|
_this.state = initialState;
|
||||||
// bind class methods with `this`
|
// bind class methods with `this`
|
||||||
_this.updateUploaderState = _this.updateUploaderState.bind(_this);
|
_this.updateUploaderState = _this.updateUploaderState.bind(_this);
|
||||||
|
_this.clearUploaderState = _this.clearUploaderState.bind(_this);
|
||||||
_this.showComponent = _this.showComponent.bind(_this);
|
_this.showComponent = _this.showComponent.bind(_this);
|
||||||
_this.stageFileAndShowDetails = _this.stageFileAndShowDetails.bind(_this);
|
_this.stageFileAndShowDetails = _this.stageFileAndShowDetails.bind(_this);
|
||||||
return _this;
|
return _this;
|
||||||
|
@ -1008,6 +1010,11 @@ var Uploader = function (_React$Component) {
|
||||||
console.log('updateUploaderState ' + name + ' ' + value);
|
console.log('updateUploaderState ' + name + ' ' + value);
|
||||||
this.setState(_defineProperty({}, name, value));
|
this.setState(_defineProperty({}, name, value));
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
key: 'clearUploaderState',
|
||||||
|
value: function clearUploaderState() {
|
||||||
|
this.setState(initialState);
|
||||||
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'showComponent',
|
key: 'showComponent',
|
||||||
value: function showComponent(component) {
|
value: function showComponent(component) {
|
||||||
|
@ -1031,6 +1038,7 @@ var Uploader = function (_React$Component) {
|
||||||
this.state.showComponent === DROPZONE && _react2.default.createElement(_dropzone2.default, { stageFileAndShowDetails: this.stageFileAndShowDetails }),
|
this.state.showComponent === DROPZONE && _react2.default.createElement(_dropzone2.default, { stageFileAndShowDetails: this.stageFileAndShowDetails }),
|
||||||
this.state.showComponent === DETAILS && _react2.default.createElement(_publishDetails2.default, {
|
this.state.showComponent === DETAILS && _react2.default.createElement(_publishDetails2.default, {
|
||||||
updateUploaderState: this.updateUploaderState,
|
updateUploaderState: this.updateUploaderState,
|
||||||
|
clearUploaderState: this.clearUploaderState,
|
||||||
file: this.state.file,
|
file: this.state.file,
|
||||||
title: this.state.title,
|
title: this.state.title,
|
||||||
channel: this.state.channel,
|
channel: this.state.channel,
|
||||||
|
@ -18398,6 +18406,7 @@ var Dropzone = function (_React$Component) {
|
||||||
_this.handleDragEnter = _this.handleDragEnter.bind(_this);
|
_this.handleDragEnter = _this.handleDragEnter.bind(_this);
|
||||||
_this.handleDragLeave = _this.handleDragLeave.bind(_this);
|
_this.handleDragLeave = _this.handleDragLeave.bind(_this);
|
||||||
_this.handleClick = _this.handleClick.bind(_this);
|
_this.handleClick = _this.handleClick.bind(_this);
|
||||||
|
_this.handleFileInput = _this.handleFileInput.bind(_this);
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18502,6 +18511,22 @@ var Dropzone = function (_React$Component) {
|
||||||
// trigger file input
|
// trigger file input
|
||||||
document.getElementById('file_input').click();
|
document.getElementById('file_input').click();
|
||||||
}
|
}
|
||||||
|
}, {
|
||||||
|
key: 'handleFileInput',
|
||||||
|
value: function handleFileInput(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
var fileList = event.target.files;
|
||||||
|
var chosenFile = fileList[0];
|
||||||
|
if (chosenFile) {
|
||||||
|
try {
|
||||||
|
this.validateFile(chosenFile); // validate the file's name, type, and size
|
||||||
|
} catch (error) {
|
||||||
|
return this.setState('fileError', error.message);
|
||||||
|
}
|
||||||
|
// stage it so it will be ready when the publish button is clicked
|
||||||
|
this.props.stageFileAndShowDetails(chosenFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'render',
|
key: 'render',
|
||||||
value: function render() {
|
value: function render() {
|
||||||
|
@ -18511,7 +18536,7 @@ var Dropzone = function (_React$Component) {
|
||||||
_react2.default.createElement(
|
_react2.default.createElement(
|
||||||
'form',
|
'form',
|
||||||
null,
|
null,
|
||||||
_react2.default.createElement('input', { className: 'input-file', type: 'file', id: 'file_input', name: 'file_input', accept: 'video/*,image/*', onChange: this.handleDrop, encType: 'multipart/form-data' })
|
_react2.default.createElement('input', { className: 'input-file', type: 'file', id: 'file_input', name: 'file_input', accept: 'video/*,image/*', onChange: this.handleFileInput, encType: 'multipart/form-data' })
|
||||||
),
|
),
|
||||||
_react2.default.createElement(
|
_react2.default.createElement(
|
||||||
'div',
|
'div',
|
||||||
|
@ -18739,7 +18764,7 @@ var PublishDetails = function (_React$Component6) {
|
||||||
_this6.showThumbnailTool = _this6.showThumbnailTool.bind(_this6);
|
_this6.showThumbnailTool = _this6.showThumbnailTool.bind(_this6);
|
||||||
_this6.hideThumbnailTool = _this6.hideThumbnailTool.bind(_this6);
|
_this6.hideThumbnailTool = _this6.hideThumbnailTool.bind(_this6);
|
||||||
_this6.publish = _this6.publish.bind(_this6);
|
_this6.publish = _this6.publish.bind(_this6);
|
||||||
_this6.cancelPublish = _this6.cancelPublish.bind(_this6);
|
_this6.clearUploaderState = _this6.clearUploaderState.bind(_this6);
|
||||||
return _this6;
|
return _this6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18764,9 +18789,9 @@ var PublishDetails = function (_React$Component6) {
|
||||||
// publish the asset
|
// publish the asset
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'cancelPublish',
|
key: 'clearUploaderState',
|
||||||
value: function cancelPublish() {
|
value: function clearUploaderState() {
|
||||||
// cancel this publish
|
this.props.clearUploaderState();
|
||||||
}
|
}
|
||||||
}, {
|
}, {
|
||||||
key: 'render',
|
key: 'render',
|
||||||
|
|
|
@ -12,6 +12,7 @@ class Dropzone extends React.Component {
|
||||||
this.handleDragEnter = this.handleDragEnter.bind(this);
|
this.handleDragEnter = this.handleDragEnter.bind(this);
|
||||||
this.handleDragLeave = this.handleDragLeave.bind(this);
|
this.handleDragLeave = this.handleDragLeave.bind(this);
|
||||||
this.handleClick = this.handleClick.bind(this);
|
this.handleClick = this.handleClick.bind(this);
|
||||||
|
this.handleFileInput = this.handleFileInput.bind(this);
|
||||||
}
|
}
|
||||||
validateFile (file) {
|
validateFile (file) {
|
||||||
if (!file) {
|
if (!file) {
|
||||||
|
@ -100,11 +101,25 @@ class Dropzone extends React.Component {
|
||||||
// trigger file input
|
// trigger file input
|
||||||
document.getElementById('file_input').click();
|
document.getElementById('file_input').click();
|
||||||
}
|
}
|
||||||
|
handleFileInput (event) {
|
||||||
|
event.preventDefault();
|
||||||
|
const fileList = event.target.files;
|
||||||
|
const chosenFile = fileList[0];
|
||||||
|
if (chosenFile) {
|
||||||
|
try {
|
||||||
|
this.validateFile(chosenFile); // validate the file's name, type, and size
|
||||||
|
} catch (error) {
|
||||||
|
return this.setState('fileError', error.message);
|
||||||
|
}
|
||||||
|
// stage it so it will be ready when the publish button is clicked
|
||||||
|
this.props.stageFileAndShowDetails(chosenFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
render () {
|
render () {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<form>
|
<form>
|
||||||
<input className="input-file" type="file" id="file_input" name="file_input" accept="video/*,image/*" onChange={this.handleDrop} encType="multipart/form-data"/>
|
<input className="input-file" type="file" id="file_input" name="file_input" accept="video/*,image/*" onChange={this.handleFileInput} encType="multipart/form-data"/>
|
||||||
</form>
|
</form>
|
||||||
<div id="primary-dropzone" className="dropzone row row--margined row--padded row--tall flex-container--column flex-container--center-center" onDrop={this.handleDrop} onDragOver={this.handleDragOver} onDragEnd={this.handleDragEnd} onDragEnter={this.handleDragEnter} onDragLeave={this.handleDragLeave} onClick={this.handleClick}>
|
<div id="primary-dropzone" className="dropzone row row--margined row--padded row--tall flex-container--column flex-container--center-center" onDrop={this.handleDrop} onDragOver={this.handleDragOver} onDragEnd={this.handleDragEnd} onDragEnter={this.handleDragEnter} onDragLeave={this.handleDragLeave} onClick={this.handleClick}>
|
||||||
<div id="primary-dropzone-instructions">
|
<div id="primary-dropzone-instructions">
|
||||||
|
|
|
@ -70,7 +70,7 @@ class PublishDetails extends React.Component {
|
||||||
this.showThumbnailTool = this.showThumbnailTool.bind(this);
|
this.showThumbnailTool = this.showThumbnailTool.bind(this);
|
||||||
this.hideThumbnailTool = this.hideThumbnailTool.bind(this);
|
this.hideThumbnailTool = this.hideThumbnailTool.bind(this);
|
||||||
this.publish = this.publish.bind(this);
|
this.publish = this.publish.bind(this);
|
||||||
this.cancelPublish = this.cancelPublish.bind(this);
|
this.clearUploaderState = this.clearUploaderState.bind(this);
|
||||||
}
|
}
|
||||||
updateUploaderState (name, value) {
|
updateUploaderState (name, value) {
|
||||||
this.props.updateUploaderState(name, value);
|
this.props.updateUploaderState(name, value);
|
||||||
|
@ -84,8 +84,8 @@ class PublishDetails extends React.Component {
|
||||||
publish () {
|
publish () {
|
||||||
// publish the asset
|
// publish the asset
|
||||||
}
|
}
|
||||||
cancelPublish () {
|
clearUploaderState () {
|
||||||
// cancel this publish
|
this.props.clearUploaderState();
|
||||||
}
|
}
|
||||||
render () {
|
render () {
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -7,11 +7,7 @@ import PublishStatus from './components/publishStatus.jsx';
|
||||||
const DROPZONE = 'DROPZONE';
|
const DROPZONE = 'DROPZONE';
|
||||||
const DETAILS = 'DETAILS';
|
const DETAILS = 'DETAILS';
|
||||||
const STATUS = 'STATUS';
|
const STATUS = 'STATUS';
|
||||||
|
const initialState = {
|
||||||
class Uploader extends React.Component {
|
|
||||||
constructor (props) {
|
|
||||||
super(props);
|
|
||||||
this.state = {
|
|
||||||
showComponent: DROPZONE, // DROPZONE, DETAILS, or PUBLISHING
|
showComponent: DROPZONE, // DROPZONE, DETAILS, or PUBLISHING
|
||||||
file : null,
|
file : null,
|
||||||
title : '',
|
title : '',
|
||||||
|
@ -21,9 +17,15 @@ class Uploader extends React.Component {
|
||||||
description : '',
|
description : '',
|
||||||
license : '',
|
license : '',
|
||||||
nsfw : '',
|
nsfw : '',
|
||||||
};
|
}
|
||||||
|
|
||||||
|
class Uploader extends React.Component {
|
||||||
|
constructor (props) {
|
||||||
|
super(props);
|
||||||
|
this.state = initialState;
|
||||||
// bind class methods with `this`
|
// bind class methods with `this`
|
||||||
this.updateUploaderState = this.updateUploaderState.bind(this);
|
this.updateUploaderState = this.updateUploaderState.bind(this);
|
||||||
|
this.clearUploaderState = this.clearUploaderState.bind(this);
|
||||||
this.showComponent = this.showComponent.bind(this);
|
this.showComponent = this.showComponent.bind(this);
|
||||||
this.stageFileAndShowDetails = this.stageFileAndShowDetails.bind(this);
|
this.stageFileAndShowDetails = this.stageFileAndShowDetails.bind(this);
|
||||||
}
|
}
|
||||||
|
@ -31,6 +33,9 @@ class Uploader extends React.Component {
|
||||||
console.log(`updateUploaderState ${name} ${value}`);
|
console.log(`updateUploaderState ${name} ${value}`);
|
||||||
this.setState({[name]: value});
|
this.setState({[name]: value});
|
||||||
}
|
}
|
||||||
|
clearUploaderState () {
|
||||||
|
this.setState(initialState);
|
||||||
|
}
|
||||||
showComponent (component) {
|
showComponent (component) {
|
||||||
this.setState({showComponent: component});
|
this.setState({showComponent: component});
|
||||||
}
|
}
|
||||||
|
@ -50,6 +55,7 @@ class Uploader extends React.Component {
|
||||||
{ this.state.showComponent === DETAILS &&
|
{ this.state.showComponent === DETAILS &&
|
||||||
<PublishDetails
|
<PublishDetails
|
||||||
updateUploaderState={this.updateUploaderState}
|
updateUploaderState={this.updateUploaderState}
|
||||||
|
clearUploaderState={this.clearUploaderState}
|
||||||
file={this.state.file}
|
file={this.state.file}
|
||||||
title={this.state.title}
|
title={this.state.title}
|
||||||
channel={this.state.channel}
|
channel={this.state.channel}
|
||||||
|
|
Loading…
Reference in a new issue