Created
June 16, 2019 17:53
-
-
Save jsmanifest/5c98da042639f64342093840452cb6da 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 from 'react' | |
import useApp from './useApp' | |
import FileUploader from './FileUploader' | |
import FileUploaderScreen from './FileUploaderScreen' | |
import FileRow from './FileRow' | |
import './styles.css' | |
const App = ({ children }) => { | |
const inputRef = React.createRef() | |
const { | |
files, | |
pending, | |
next, | |
uploading, | |
uploaded, | |
status, | |
onSubmit, | |
onChange, | |
triggerInput, | |
getFileUploaderProps, | |
} = useApp({ inputRef }) | |
const initialFileUploaderProps = getFileUploaderProps({ | |
triggerInput: status === 'IDLE' ? triggerInput : undefined, | |
onChange: status === 'IDLE' ? onChange : undefined, | |
}) | |
return ( | |
<form className="form" onSubmit={onSubmit}> | |
<FileUploader {...initialFileUploaderProps}> | |
<FileUploaderScreen | |
triggerInput={triggerInput} | |
getFileUploaderProps={getFileUploaderProps} | |
files={files} | |
pending={pending} | |
status={status} | |
/> | |
</FileUploader> | |
<div className={files.length ? 'file-list' : ''}> | |
{files.map(({ id, ...rest }, index) => ( | |
<FileRow | |
key={`thumb${index}`} | |
isUploaded={!!uploaded[id]} | |
isUploading={next && next.id === id} | |
id={id} | |
{...rest} | |
/> | |
))} | |
</div> | |
</form> | |
) | |
} | |
export default App |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment