moved start logic to exportModal from exportInit

This commit is contained in:
Abhinav-grd 2021-07-08 12:50:20 +05:30
parent 4a4accc4d4
commit 04e1b80cae
3 changed files with 18 additions and 16 deletions

View file

@ -2,26 +2,17 @@ import { DeadCenter } from 'pages/gallery';
import React from 'react';
import { Button } from 'react-bootstrap';
import constants from 'utils/strings/constants';
import { ExportStage } from './ExportModal';
interface Props {
show: boolean
onHide: () => void
updateExportFolder: (newFolder: string) => void;
updateExportStage: (newState: ExportStage) => void;
exportFolder: string
exportFiles: () => void
startExport: () => void
exportSize: string;
selectExportDirectory: () => void
}
export default function ExportInit(props: Props) {
const startExport = async () => {
if (!props.exportFolder) {
await props.selectExportDirectory();
}
props.exportFiles();
props.updateExportStage(ExportStage.INPROGRESS);
};
return (
<>
<DeadCenter >
@ -35,7 +26,7 @@ export default function ExportInit(props: Props) {
flex: 1,
whiteSpace: 'nowrap',
}}
onClick={startExport}
onClick={props.startExport}
>{constants.START}</Button>
</DeadCenter>
</>

View file

@ -79,7 +79,14 @@ export default function ExportModal(props: Props) {
setData(LS_KEYS.EXPORT, { ...getData(LS_KEYS.EXPORT), time: newTime });
};
const startExport = () => {
const startExport = async () => {
if (!exportFolder) {
const folderSelected = await selectExportDirectory();
if (!folderSelected) {
// no-op as select folder aborted
return;
}
}
updateExportStage(ExportStage.INPROGRESS);
setExportStats({ current: 0, total: 0, failed: 0 });
exportService.exportFiles(setExportStats);
@ -87,7 +94,12 @@ export default function ExportModal(props: Props) {
const selectExportDirectory = async () => {
const newFolder = await exportService.selectExportDirectory();
newFolder && updateExportFolder(newFolder);
if (newFolder) {
updateExportFolder(newFolder);
return true;
} else {
return false;
}
};
const cancelExport = () => {
@ -111,8 +123,7 @@ export default function ExportModal(props: Props) {
exportFolder={exportFolder}
exportSize={exportSize}
updateExportFolder={updateExportFolder}
exportFiles={startExport}
updateExportStage={updateExportStage}
startExport={startExport}
selectExportDirectory={selectExportDirectory}
/>
);

View file

@ -61,7 +61,7 @@ class ExportService {
try {
const dir = getData(LS_KEYS.EXPORT).folder;
if (!dir) {
// directory selector closed
// no-export folder set
return;
}
const exportedFiles: Set<string> = await this.ElectronAPIs.getExportedFiles(