Created
July 6, 2017 09:13
-
-
Save ernestofreyreg/db1d9e59521c356e3d9bbe39da593b0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {Component} from 'react' | |
import PropTypes from 'prop-types' | |
import FileDrop from './FileDrop' | |
import FileUploadProgress from './FileUploadProgress' | |
import {createActions, initialState} from './uploader' | |
import connect from '../connect' | |
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} | |
/> | |
) | |
} | |
} | |
export default connect(FileUploader, createActions, initialState) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment