Skip to content

Commit

Permalink
fix(j-s): fix files being displayed in progress state (#8710)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
Arnarkari93 and kodiakhq[bot] authored Oct 18, 2022
1 parent 2a0c1be commit da9c333
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ const UploadFilesToPoliceCase: React.FC<{
}, [setAllUploaded, displayFiles])

const setSingleFile = useCallback(
(displayFile) => {
(displayFile: UploadFile, newId?: string) => {
setDisplayFiles((previous) => {
const index = previous.findIndex((f) => f.id === displayFile.id)
if (index === -1) {
return previous
}
const next = [...previous]
next[index] = displayFile
next[index] = { ...displayFile, id: newId ?? displayFile.id }
return next
})
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,10 @@ export const useS3UploadV2 = (
>(DeleteFileMutationDocument)

const upload = useCallback(
(files: Array<[File, string]>, updateFile: (file: UploadFile) => void) => {
(
files: Array<[File, string]>,
updateFile: (file: UploadFile, newId?: string) => void,
) => {
files.forEach(async ([file, id]) => {
try {
const data = await createPresignedMutation({
Expand Down Expand Up @@ -124,13 +127,16 @@ export const useS3UploadV2 = (
throw Error('failed to add file to case')
}

updateFile({
name: file.name,
percent: 100,
status: 'done',
// We need to set the id so we are able to delete the file later
id: data2.data.createFile.id,
})
updateFile(
{
id: id,
name: file.name,
percent: 100,
status: 'done',
// We need to set the id so we are able to delete the file later
},
data2.data.createFile.id,
)
} catch (e) {
updateFile({
id: id,
Expand Down

0 comments on commit da9c333

Please sign in to comment.