From e6d0bb77c86f9374aadd0c18758aa35f9e1469b9 Mon Sep 17 00:00:00 2001 From: Antonin Cezard Date: Wed, 30 Aug 2023 09:44:13 +0200 Subject: [PATCH] feat: add native upload resume has to be put at a better location --- src/drive/web/modules/views/Drive/index.jsx | 41 ++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/drive/web/modules/views/Drive/index.jsx b/src/drive/web/modules/views/Drive/index.jsx index f2ecf7b9da..441d1c14b8 100644 --- a/src/drive/web/modules/views/Drive/index.jsx +++ b/src/drive/web/modules/views/Drive/index.jsx @@ -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' @@ -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) @@ -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)