Skip to content

Commit

Permalink
rewrite to allow zip and folder import
Browse files Browse the repository at this point in the history
  • Loading branch information
sijumoncy committed Feb 19, 2024
1 parent 19bf0a3 commit a98cf8a
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions renderer/src/layouts/projects/ImportProjectPopUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,24 @@ 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}))
}

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]
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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]);
Expand Down Expand Up @@ -308,9 +311,19 @@ export default function ImportProjectPopUp(props) {
</div>

<div>
<h4 className="text-red-500">{valid === true ? t('label-enter-location') : (sbData?.fileExist ? '' : t('dynamic-msg-unable-find-buritto-snack'))}</h4>
<h4 className="text-red-500">{valid === true ? t('label-enter-location') : ((sbData?.fileExist || !folderPath) ? '' : t('dynamic-msg-unable-find-buritto-snack'))}</h4>
</div>

{/* check zip or folder */}
{!folderPath && (
<div className="w-full flex">
<div className="flex flex-row justify-end mr-3">
<input id="visible_1" className="visible" type="checkbox" checked={importingIsZip} onClick={() => setImportingIsZip(!importingIsZip)} />
<span className="ml-2 text-xs font-bold" title="">Project as zip</span>
</div>
</div>
)}

</div>

{sbData?.fileExist
Expand Down Expand Up @@ -348,7 +361,7 @@ export default function ImportProjectPopUp(props) {
</label>
)}
</div>
)}
) }

<div className="flex gap-6 mb-5 justify-end">

Expand Down

0 comments on commit a98cf8a

Please sign in to comment.