From 9d01580396b366b613905984ee4546fdc7043d1f Mon Sep 17 00:00:00 2001 From: Abhinav Date: Mon, 27 Mar 2023 13:54:37 +0530 Subject: [PATCH] removed ExportStats and used new export service function syncUpdatedFileCounts --- src/components/ExportFinished.tsx | 2 -- src/components/ExportModal.tsx | 34 ++++++++----------------------- src/types/export/index.ts | 4 ---- 3 files changed, 8 insertions(+), 32 deletions(-) diff --git a/src/components/ExportFinished.tsx b/src/components/ExportFinished.tsx index 59bff708b..731c653b5 100644 --- a/src/components/ExportFinished.tsx +++ b/src/components/ExportFinished.tsx @@ -7,7 +7,6 @@ import { } from '@mui/material'; import React from 'react'; import { t } from 'i18next'; -import { ExportStats } from 'types/export'; import { formatDateTime } from 'utils/time/format'; import { SpaceBetweenFlex } from './Container'; @@ -15,7 +14,6 @@ interface Props { pendingFileCount: number; onHide: () => void; lastExportTime: number; - exportStats: ExportStats; startExport: () => void; } diff --git a/src/components/ExportModal.tsx b/src/components/ExportModal.tsx index 2a8651ecc..78b36d022 100644 --- a/src/components/ExportModal.tsx +++ b/src/components/ExportModal.tsx @@ -1,7 +1,7 @@ import isElectron from 'is-electron'; import React, { useEffect, useState, useContext } from 'react'; import exportService from 'services/exportService'; -import { ExportProgress, ExportSettings, ExportStats } from 'types/export'; +import { ExportProgress, ExportSettings } from 'types/export'; import { Box, Button, @@ -55,10 +55,6 @@ export default function ExportModal(props: Props) { current: 0, total: 0, }); - const [exportStats, setExportStats] = useState({ - failed: 0, - success: 0, - }); const [lastExportTime, setLastExportTime] = useState(0); // ==================== @@ -84,7 +80,7 @@ export default function ExportModal(props: Props) { useEffect(() => { try { if (continuousExport) { - exportService.enableContinuousExport(startExport); + exportService.enableContinuousExport(runExport); } else { exportService.disableContinuousExport(); } @@ -102,12 +98,8 @@ export default function ExportModal(props: Props) { const exportInfo = await exportService.getExportRecord(); setExportStage(exportInfo?.stage ?? ExportStage.INIT); setLastExportTime(exportInfo?.lastAttemptTimestamp); - setExportStats({ - success: exportInfo?.exportedFiles?.length ?? 0, - failed: exportInfo?.failedFiles?.length ?? 0, - }); if (exportInfo?.stage === ExportStage.INPROGRESS) { - await startExport(); + await runExport(); } } catch (e) { logError(e, 'error handling exportFolder change'); @@ -170,14 +162,7 @@ export default function ExportModal(props: Props) { const postExportRun = async () => { await updateExportStage(ExportStage.FINISHED); await updateExportTime(Date.now()); - await syncExportStatsWithRecord(); - }; - - const syncExportStatsWithRecord = async () => { - const exportRecord = await exportService.getExportRecord(); - const failed = exportRecord?.failedFiles?.length ?? 0; - const success = exportRecord?.exportedFiles?.length ?? 0; - setExportStats({ failed, success }); + exportService.syncUpdatedFileCounts(); }; // ============= @@ -200,12 +185,10 @@ export default function ExportModal(props: Props) { } }; - const startExport = async () => { + const runExport = async () => { try { await preExportRun(); - - await exportService.exportFiles(setExportProgress); - + await exportService.runExport(setExportProgress); await postExportRun(); } catch (e) { logError(e, 'startExport failed'); @@ -226,7 +209,7 @@ export default function ExportModal(props: Props) { case ExportStage.INIT: return ( ); @@ -246,8 +229,7 @@ export default function ExportModal(props: Props) { pendingFileCount={pendingFileCount} onHide={props.onHide} lastExportTime={lastExportTime} - exportStats={exportStats} - startExport={startExport} + startExport={runExport} /> ); diff --git a/src/types/export/index.ts b/src/types/export/index.ts index 724788574..2f5241433 100644 --- a/src/types/export/index.ts +++ b/src/types/export/index.ts @@ -9,10 +9,6 @@ export interface ExportProgress { export interface ExportedCollectionPaths { [collectionID: number]: string; } -export interface ExportStats { - failed: number; - success: number; -} export interface ExportRecordV1 { version?: number;