removed ExportStats and used new export service function syncUpdatedFileCounts

This commit is contained in:
Abhinav 2023-03-27 13:54:37 +05:30
parent 89b1b734c9
commit 9d01580396
3 changed files with 8 additions and 32 deletions

View file

@ -7,7 +7,6 @@ import {
} from '@mui/material'; } from '@mui/material';
import React from 'react'; import React from 'react';
import { t } from 'i18next'; import { t } from 'i18next';
import { ExportStats } from 'types/export';
import { formatDateTime } from 'utils/time/format'; import { formatDateTime } from 'utils/time/format';
import { SpaceBetweenFlex } from './Container'; import { SpaceBetweenFlex } from './Container';
@ -15,7 +14,6 @@ interface Props {
pendingFileCount: number; pendingFileCount: number;
onHide: () => void; onHide: () => void;
lastExportTime: number; lastExportTime: number;
exportStats: ExportStats;
startExport: () => void; startExport: () => void;
} }

View file

@ -1,7 +1,7 @@
import isElectron from 'is-electron'; import isElectron from 'is-electron';
import React, { useEffect, useState, useContext } from 'react'; import React, { useEffect, useState, useContext } from 'react';
import exportService from 'services/exportService'; import exportService from 'services/exportService';
import { ExportProgress, ExportSettings, ExportStats } from 'types/export'; import { ExportProgress, ExportSettings } from 'types/export';
import { import {
Box, Box,
Button, Button,
@ -55,10 +55,6 @@ export default function ExportModal(props: Props) {
current: 0, current: 0,
total: 0, total: 0,
}); });
const [exportStats, setExportStats] = useState<ExportStats>({
failed: 0,
success: 0,
});
const [lastExportTime, setLastExportTime] = useState(0); const [lastExportTime, setLastExportTime] = useState(0);
// ==================== // ====================
@ -84,7 +80,7 @@ export default function ExportModal(props: Props) {
useEffect(() => { useEffect(() => {
try { try {
if (continuousExport) { if (continuousExport) {
exportService.enableContinuousExport(startExport); exportService.enableContinuousExport(runExport);
} else { } else {
exportService.disableContinuousExport(); exportService.disableContinuousExport();
} }
@ -102,12 +98,8 @@ export default function ExportModal(props: Props) {
const exportInfo = await exportService.getExportRecord(); const exportInfo = await exportService.getExportRecord();
setExportStage(exportInfo?.stage ?? ExportStage.INIT); setExportStage(exportInfo?.stage ?? ExportStage.INIT);
setLastExportTime(exportInfo?.lastAttemptTimestamp); setLastExportTime(exportInfo?.lastAttemptTimestamp);
setExportStats({
success: exportInfo?.exportedFiles?.length ?? 0,
failed: exportInfo?.failedFiles?.length ?? 0,
});
if (exportInfo?.stage === ExportStage.INPROGRESS) { if (exportInfo?.stage === ExportStage.INPROGRESS) {
await startExport(); await runExport();
} }
} catch (e) { } catch (e) {
logError(e, 'error handling exportFolder change'); logError(e, 'error handling exportFolder change');
@ -170,14 +162,7 @@ export default function ExportModal(props: Props) {
const postExportRun = async () => { const postExportRun = async () => {
await updateExportStage(ExportStage.FINISHED); await updateExportStage(ExportStage.FINISHED);
await updateExportTime(Date.now()); await updateExportTime(Date.now());
await syncExportStatsWithRecord(); exportService.syncUpdatedFileCounts();
};
const syncExportStatsWithRecord = async () => {
const exportRecord = await exportService.getExportRecord();
const failed = exportRecord?.failedFiles?.length ?? 0;
const success = exportRecord?.exportedFiles?.length ?? 0;
setExportStats({ failed, success });
}; };
// ============= // =============
@ -200,12 +185,10 @@ export default function ExportModal(props: Props) {
} }
}; };
const startExport = async () => { const runExport = async () => {
try { try {
await preExportRun(); await preExportRun();
await exportService.runExport(setExportProgress);
await exportService.exportFiles(setExportProgress);
await postExportRun(); await postExportRun();
} catch (e) { } catch (e) {
logError(e, 'startExport failed'); logError(e, 'startExport failed');
@ -226,7 +209,7 @@ export default function ExportModal(props: Props) {
case ExportStage.INIT: case ExportStage.INIT:
return ( return (
<ExportInit <ExportInit
startExport={startExport} startExport={runExport}
totalFileCount={totalFileCount} totalFileCount={totalFileCount}
/> />
); );
@ -246,8 +229,7 @@ export default function ExportModal(props: Props) {
pendingFileCount={pendingFileCount} pendingFileCount={pendingFileCount}
onHide={props.onHide} onHide={props.onHide}
lastExportTime={lastExportTime} lastExportTime={lastExportTime}
exportStats={exportStats} startExport={runExport}
startExport={startExport}
/> />
); );

View file

@ -9,10 +9,6 @@ export interface ExportProgress {
export interface ExportedCollectionPaths { export interface ExportedCollectionPaths {
[collectionID: number]: string; [collectionID: number]: string;
} }
export interface ExportStats {
failed: number;
success: number;
}
export interface ExportRecordV1 { export interface ExportRecordV1 {
version?: number; version?: number;