Skip to content

Instantly share code, notes, and snippets.

@ernestofreyreg
Last active July 6, 2017 06:02
Show Gist options
  • Save ernestofreyreg/bdb0a06252a34e5f575febca6937de3f to your computer and use it in GitHub Desktop.
Save ernestofreyreg/bdb0a06252a34e5f575febca6937de3f to your computer and use it in GitHub Desktop.
class FileUploader extends Component {
static propTypes = {
uploadingFile: PropTypes.object,
uploadProgress: PropTypes.object,
cancelled: PropTypes.bool,
completed: PropTypes.bool,
uploadFile: PropTypes.func.isRequired,
cancelUpload: PropTypes.func.isRequired,
retryUpload: PropTypes.func.isRequired
}
handleDrop = acceptedfiles => {
// Just upload first file
this.props.uploadFile(acceptedfiles[0])
}
handleCancelUpload = () => {
this.props.cancelUpload()
}
handleRetry = () => {
this.props.retryUpload()
}
render () {
const {
uploadingFile,
uploadProgress,
cancelled,
completed
} = this.props
if (!uploadingFile) {
return <FileDrop onDrop={this.handleDrop} />
}
return (
<FileUploadProgress
file={uploadingFile}
progress={uploadProgress}
cancelled={cancelled}
completed={completed}
onCancel={this.handleCancelUpload}
onRetry={this.handleRetry}
/>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment