diff --git a/src/components/pages/gallery/UploadTypeChoiceModal.tsx b/src/components/pages/gallery/UploadTypeChoiceModal.tsx index c654c10c2..6baf7c4be 100644 --- a/src/components/pages/gallery/UploadTypeChoiceModal.tsx +++ b/src/components/pages/gallery/UploadTypeChoiceModal.tsx @@ -5,6 +5,7 @@ import constants from 'utils/strings/constants'; import { IoIosArrowForward, IoMdClose } from 'react-icons/io'; import FileUploadIcon from 'components/icons/FileUploadIcon'; import FolderUploadIcon from 'components/icons/FolderUploadIcon'; +import { BsGoogle } from 'react-icons/bs'; export default function UploadTypeChoiceModal({ setElectronFiles, @@ -19,6 +20,7 @@ export default function UploadTypeChoiceModal({ const uploadFiles = async () => { const files = await ImportService.showUploadFilesDialog(); hideFiletypeDialog(); + ImportService.setSkipUpdatePendingUploads(false); setIsUploadDirs(false); setElectronFiles(files); }; @@ -26,10 +28,24 @@ export default function UploadTypeChoiceModal({ const uploadDirs = async () => { const files = await ImportService.showUploadDirsDialog(); hideFiletypeDialog(); + ImportService.setSkipUpdatePendingUploads(false); setIsUploadDirs(true); setElectronFiles(files); }; + const uploadGoogleTakeout = async () => { + const filePaths = await ImportService.showUploadZipDialog(); + hideFiletypeDialog(); + if (filePaths?.length > 0) { + const files = await ImportService.getElectronFilesFromGoogleZip( + filePaths[0] + ); + ImportService.setSkipUpdatePendingUploads(true); + setIsUploadDirs(true); + setElectronFiles(files); + } + }; + return ( + + + diff --git a/src/services/importService.ts b/src/services/importService.ts index 828c8506c..9147ef08f 100644 --- a/src/services/importService.ts +++ b/src/services/importService.ts @@ -5,12 +5,25 @@ import { runningInBrowser } from 'utils/common'; class ImportService { ElectronAPIs: any; private allElectronAPIsExist: boolean = false; + private skipUpdatePendingUploads = false; constructor() { this.ElectronAPIs = runningInBrowser() && window['ElectronAPIs']; this.allElectronAPIsExist = !!this.ElectronAPIs?.exists; } + setSkipUpdatePendingUploads(skip: boolean) { + this.skipUpdatePendingUploads = skip; + } + + async getElectronFilesFromGoogleZip( + zipPath: string + ): Promise { + if (this.allElectronAPIsExist) { + return this.ElectronAPIs.getElectronFilesFromGoogleZip(zipPath); + } + } + async showUploadFilesDialog(): Promise { if (this.allElectronAPIsExist) { return this.ElectronAPIs.showUploadFilesDialog(); @@ -23,6 +36,12 @@ class ImportService { } } + async showUploadZipDialog(): Promise { + if (this.allElectronAPIsExist) { + return this.ElectronAPIs.showUploadZipDialog(); + } + } + async getPendingUploads() { if (this.allElectronAPIsExist) { const { files, collectionName } = @@ -41,7 +60,7 @@ class ImportService { files: FileWithCollection[], collections: Collection[] ) { - if (this.allElectronAPIsExist) { + if (this.allElectronAPIsExist && !this.skipUpdatePendingUploads) { let collectionName: string; if (collections.length === 1) { collectionName = collections[0].name; @@ -54,7 +73,7 @@ class ImportService { } updatePendingUploads(files: FileWithCollection[]) { - if (this.allElectronAPIsExist) { + if (this.allElectronAPIsExist && !this.skipUpdatePendingUploads) { const filePaths = files.map( (file) => (file.file as ElectronFile).path );