Commit e0c8a470 authored by charlyjazz's avatar charlyjazz
Browse files

Optimize app and add message when file is invalid

parent 2a74bcba
......@@ -59,7 +59,7 @@ function onReadError(ctx, message) {
}
});
ctx.setState({done: true});
ctx.setState({invalid: true});
}
......
......@@ -18,13 +18,16 @@ export default class DropFileInput extends Component {
handlerOnDrop = event => {
event.preventDefault();
for(let i = 0; i < event.dataTransfer.files.length; i++) {
this.setState({
files: [...this.state.files, ...[event.dataTransfer.files[i]]]
});
let array_files = [];
for (let i = 0; i < event.dataTransfer.files.length; i++) {
array_files.push(event.dataTransfer.files[i]);
}
this.setState({uploading: false})
this.setState({files: [...this.state.files, ...array_files]});
this.setState({uploading: false});
};
toggleUpload = () => {
......
......@@ -11,6 +11,7 @@ export default class File extends Component {
this.state = {
uploading: props.uploading,
done: false,
invalid: false,
server_filename: '',
progress: {
percent: 0
......@@ -23,11 +24,10 @@ export default class File extends Component {
componentWillReceiveProps(nextProps) {
const that = this;
if (nextProps.uploading && !this.state.done) {
if (nextProps.uploading && !this.state.done && !this.state.invalid) {
io.emit('start-transfer', this.props.file.name, this.props.file.size, function(filename) {
if (!filename) {
// The server rejected the transfer
that.onReadError();
that.onReadError(); // The server rejected the transfer
}
else {
that.setState({server_filename: filename}, () => {
......@@ -44,16 +44,16 @@ export default class File extends Component {
<span className="File-name">Name: {this.props.file.name}</span>
<span className="File-type">Type: {this.props.file.type || 'unknown'}</span>
<span className="File-type">Size: {this.props.file.size}</span>
{ this.props.uploading &&
<Line percent={this.state.progress.percent}
strokeColor={this.state.progress.color}
strokeWidth="1"
strokeLinecap='square'
trailColor="#2fb9e224"/>
<Line percent={this.state.progress.percent}
strokeColor={this.state.progress.color}
strokeWidth="1"
strokeLinecap='square'
trailColor="#2fb9e224"/>
}
{ this.state.done && "Done"}
{ this.state.done && "Done" }
{ this.state.invalid && "Invalid" }
</div>
)
}
}
}
\ No newline at end of file
......@@ -20,7 +20,6 @@
"webpack": "^3.8.1"
},
"dependencies": {
"backbone-collection": "^1.0.10",
"rc-progress": "^2.2.2",
"react": "^16.0.0",
"react-dom": "^16.0.0",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment