Last active
April 4, 2020 19:56
-
-
Save jimjeffers/dbbdd3fa0f8b4c14645c9b62089f7a90 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
// Track a completed download and use an effect to update the status | |
// of the associated upload via the latest component state. | |
const [finishedDownload, setFinishedDownload] = useState(null as string | null) | |
useEffect(() => { | |
if (!finishedDownload) { return } | |
const updatedPreview = localPreviews[finishedDownload] | |
if (localPreviews[finishedDownload].status !== FileUploadStatus.Available) { | |
const normalizedPreviews = mergePreviewsToState([{ ...updatedPreview, status: FileUploadStatus.Available }], localPreviews) | |
setLocalPreviews(normalizedPreviews) | |
const save = async () => { | |
await savePreviews(normalizedPreviews) | |
} | |
save() | |
} | |
}, [finishedDownload, localPreviews, setLocalPreviews]) | |
const handleCompletedUploaded: HandleFileUploadFn = preview => { | |
setFinishedDownload(preview.id) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment