[web] fix upload when file is overwritten (in Safari) (#19287)

* [web] fix upload when file is overwritten (in Safari)

* remove setTimeout

* set uppyOptions before uploading with overwrite

GitOrigin-RevId: ded444e25a19de3f662ffc3718b3d26fc389b413
This commit is contained in:
Domagoj Kriskovic 2024-07-09 14:58:29 +02:00 committed by Copybot
parent f63de6779d
commit a651eec4c4

View file

@ -1,5 +1,5 @@
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { useCallback, useEffect, useRef, useState } from 'react' import { useCallback, useEffect, useState } from 'react'
import Uppy from '@uppy/core' import Uppy from '@uppy/core'
import XHRUpload from '@uppy/xhr-upload' import XHRUpload from '@uppy/xhr-upload'
import { Dashboard } from '@uppy/react' import { Dashboard } from '@uppy/react'
@ -87,11 +87,6 @@ export default function FileTreeUploadDoc() {
return endpoint return endpoint
} }
const overwriteRef = useRef(overwrite)
useEffect(() => {
overwriteRef.current = overwrite
}, [overwrite])
// initialise the Uppy object // initialise the Uppy object
const [uppy] = useState(() => { const [uppy] = useState(() => {
const endpoint = buildEndpoint(projectId, parentFolderId) const endpoint = buildEndpoint(projectId, parentFolderId)
@ -115,15 +110,11 @@ export default function FileTreeUploadDoc() {
} }
}, },
onBeforeUpload(files) { onBeforeUpload(files) {
if (overwriteRef.current) {
return true
} else {
const conflicts = buildConflicts(files) const conflicts = buildConflicts(files)
const folderConflicts = buildFolderConflicts(files) const folderConflicts = buildFolderConflicts(files)
setConflicts(conflicts) setConflicts(conflicts)
setFolderConflicts(folderConflicts) setFolderConflicts(folderConflicts)
return conflicts.length === 0 && folderConflicts.length === 0 return conflicts.length === 0 && folderConflicts.length === 0
}
}, },
autoProceed: true, autoProceed: true,
}) })
@ -214,9 +205,13 @@ export default function FileTreeUploadDoc() {
// handle forced overwriting of conflicting files // handle forced overwriting of conflicting files
const handleOverwrite = useCallback(() => { const handleOverwrite = useCallback(() => {
setOverwrite(true) setOverwrite(true)
window.setTimeout(() => { uppy.setOptions({
onBeforeUpload() {
// don't check for file conflicts
return true
},
})
uppy.upload() uppy.upload()
}, 10)
}, [uppy]) }, [uppy])
// whether to show a message about conflicting files // whether to show a message about conflicting files