Skip to content

Commit

Permalink
Handle reset uploader state
Browse files Browse the repository at this point in the history
see issue kimmelsg#21
  • Loading branch information
koox00 committed Oct 12, 2017
1 parent 7206e0c commit 45c2e3c
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ export default class Uploader extends React.Component {
if (this.props.uploadOnSelection) this.handleUpload(files);
}

handleReset() {
this.setState({
response: null,
status: null,
error: null,
aborted: null,
complete: false,
progress: 0,
});
}

handleUpload(files = this.state.files) {
let { progress } = this.state;
let { request, onComplete, reset } = this.props;
Expand All @@ -46,15 +57,6 @@ export default class Uploader extends React.Component {
if (error) return this.setState({ error, response, status });
if (aborted) return this.setState({ aborted });
if (onComplete) onComplete({ response, status });
if (reset)
return this.setState({
response: null,
status: null,
error: null,
aborted: null,
complete: false,
progress: 0,
});
this.setState({ response, status, complete: true });
});
}
Expand All @@ -66,6 +68,7 @@ export default class Uploader extends React.Component {
...this.state,
onFiles: files => this.handleFiles(files),
startUpload: () => this.handleUpload(),
onReset: () => this.handleReset(),
});
}
}

0 comments on commit 45c2e3c

Please sign in to comment.