1
0
mirror of https://github.com/ascribe/onion.git synced 2025-01-20 17:51:25 +01:00

Rearrange handleDrop() to flow more naturally

This commit is contained in:
Brett Sun 2015-12-02 13:52:17 +01:00
parent fe24a5e15a
commit 916ec7aace

View File

@ -59,11 +59,9 @@ let FileDragAndDrop = React.createClass({
handleDrop(event) { handleDrop(event) {
event.preventDefault(); event.preventDefault();
event.stopPropagation(); event.stopPropagation();
let files;
if(this.props.dropzoneInactive) { if (!this.props.dropzoneInactive) {
return; let files;
}
// handle Drag and Drop // handle Drag and Drop
if(event.dataTransfer && event.dataTransfer.files.length > 0) { if(event.dataTransfer && event.dataTransfer.files.length > 0) {
@ -75,7 +73,7 @@ let FileDragAndDrop = React.createClass({
if(typeof this.props.onDrop === 'function' && files) { if(typeof this.props.onDrop === 'function' && files) {
this.props.onDrop(files); this.props.onDrop(files);
} }
}
}, },
handleDeleteFile(fileId) { handleDeleteFile(fileId) {
@ -107,14 +105,10 @@ let FileDragAndDrop = React.createClass({
}, },
handleOnClick() { handleOnClick() {
// do not propagate event if the drop zone's inactive,
// for example when multiple is set to false and the user already uploaded a piece
if (!this.props.dropzoneInactive) {
let evt; let evt;
// when multiple is set to false and the user already uploaded a piece,
// do not propagate event
if(this.props.dropzoneInactive) {
// if there is a handle function for doing stuff
// when the dropzone is inactive, then call it
return;
}
try { try {
evt = new MouseEvent('click', { evt = new MouseEvent('click', {
@ -129,6 +123,7 @@ let FileDragAndDrop = React.createClass({
} }
this.refs.fileSelector.getDOMNode().dispatchEvent(evt); this.refs.fileSelector.getDOMNode().dispatchEvent(evt);
}
}, },
render: function () { render: function () {