From a98cf8ab48c2f53160ba037f649743ac9ce7affe Mon Sep 17 00:00:00 2001 From: sijumoncy <72241997+sijumoncy@users.noreply.github.com> Date: Mon, 19 Feb 2024 18:00:13 +0530 Subject: [PATCH] rewrite to allow zip and folder import --- .../layouts/projects/ImportProjectPopUp.js | 27 ++++++++++++++----- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/renderer/src/layouts/projects/ImportProjectPopUp.js b/renderer/src/layouts/projects/ImportProjectPopUp.js index 4a4b747f..436bd2fe 100644 --- a/renderer/src/layouts/projects/ImportProjectPopUp.js +++ b/renderer/src/layouts/projects/ImportProjectPopUp.js @@ -63,6 +63,8 @@ export default function ImportProjectPopUp(props) { logger.debug('ImportProjectPopUp.js', `Closing the Dialog box : Triggered from : ${triggeredFrom}`); removeExtractedZipDir() setValid(false); + setSbData() + setFolderPath() closePopUp(false); setShow(false); setImportProgress((prev)=>({...prev, importStarted:false, completedSteps: 0, totalSteps: 4})) @@ -70,15 +72,15 @@ export default function ImportProjectPopUp(props) { const openFileDialogSettingData = async () => { logger.debug('ImportProjectPopUp.js', 'Inside openFileDialogSettingData'); - // const options = { properties: ['openDirectory', 'openFile'] }; - const options = { properties: [] }; + // const options = { properties: ['openFile','openDirectory'] }; + const options = importingIsZip ? { properties: ['openFile'], filters: [{name:'zip file', extensions:["zip"]}] } : { properties: ['openDirectory'] }; const { dialog } = window.require('@electron/remote'); const chosenFolder = await dialog.showOpenDialog(options); let selectedFolderPath; if ((chosenFolder.filePaths).length > 0) { logger.debug('ImportProjectPopUp.js', 'Selected a directory'); await localforage.getItem('userProfile').then(async (value) => { - setShow(true); + // setShow(true); setCurrentUser(value.username) // Adding 'projects' to check the duplication in the user project resources list selectedFolderPath = chosenFolder.filePaths[0] @@ -109,7 +111,7 @@ export default function ImportProjectPopUp(props) { const path = require('path'); const fs = window.require('fs'); // delete the extracted zip file after successfull / failed import - if(importingIsZip) { + if(importingIsZip && folderPath) { setImportingIsZip(false) if (fs.existsSync(path.join(folderPath))) { await fs.rmdirSync(path.join(folderPath), { recursive: true }, async (err) => { @@ -225,7 +227,8 @@ export default function ImportProjectPopUp(props) { React.useEffect(() => { if (open) { setImportProgress((prev)=>({...prev, importStarted:false, completedSteps: 0, totalSteps: 4})) - openFileDialogSettingData(); + // openFileDialogSettingData(); + setShow(true); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [open]); @@ -308,9 +311,19 @@ export default function ImportProjectPopUp(props) {