Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Created June 16, 2019 17:53
Show Gist options
  • Save jsmanifest/5c98da042639f64342093840452cb6da to your computer and use it in GitHub Desktop.
Save jsmanifest/5c98da042639f64342093840452cb6da to your computer and use it in GitHub Desktop.
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