Skip to content

Commit

Permalink
feat: add native upload resume
Browse files Browse the repository at this point in the history
has to be put at a better location
  • Loading branch information
acezard committed Aug 30, 2023
1 parent 915ba65 commit e6d0bb7
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/drive/web/modules/views/Drive/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import { useQuery, useClient } from 'cozy-client'
import { useVaultClient } from 'cozy-keys-lib'
import { useI18n } from 'cozy-ui/transpiled/react/I18n'
import useBreakpoints from 'cozy-ui/transpiled/react/hooks/useBreakpoints'

import { useWebviewIntent } from 'cozy-intent'
import {
removeFileToUploadQueue,
uploadFilesFromNative,
purgeUploadQueue
} from 'drive/web/modules/upload'
import Dropzone from 'drive/web/modules/upload/Dropzone'
import { ModalContext } from 'drive/lib/ModalContext'
import useActions from 'drive/web/modules/actions/useActions'
Expand Down Expand Up @@ -62,6 +67,7 @@ const DriveView = () => {
const currentFolderId = useCurrentFolderId() || ROOT_DIR_ID
useHead()
const { isSelectionBarVisible } = useSelectionContext()
const webviewIntent = useWebviewIntent()

const { isMobile } = useBreakpoints()
const { isFabDisplayed, setIsFabDisplayed } = useContext(FabContext)
Expand Down Expand Up @@ -172,6 +178,39 @@ const DriveView = () => {
}),
[t]
)

useEffect(() => {
if (!webviewIntent) return

webviewIntent
.call('hasFilesToHandle')
.then(({ filesToHandle, uploadedFiles, uploading }) => {
if (!uploading) return false

actions.dispatch(
uploadFilesFromNative(
filesToHandle,
displayedFolder.id,
undefined,
{ client },
() => Promise.resolve()
)
)

return uploadedFiles
})
.then(uploadedFiles => {
if (!uploadedFiles) return false

return uploadedFiles.forEach(file => {
return actions.dispatch(removeFileToUploadQueue(file))
})
})
.catch(() => {
return actions.dispatch(purgeUploadQueue())
})
}, [actions, client, displayedFolder.id, webviewIntent])

useEffect(() => {
if (canWriteToCurrentFolder) {
setIsFabDisplayed(isMobile)
Expand Down

0 comments on commit e6d0bb7

Please sign in to comment.