From 2424767e79c1699b19b27683baca72a406657a35 Mon Sep 17 00:00:00 2001 From: Abhinav Date: Tue, 7 Dec 2021 12:54:11 +0530 Subject: [PATCH] null safe variable --- src/components/ExportModal.tsx | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/components/ExportModal.tsx b/src/components/ExportModal.tsx index f30956646..f7c3c6c80 100644 --- a/src/components/ExportModal.tsx +++ b/src/components/ExportModal.tsx @@ -115,8 +115,8 @@ export default function ExportModal(props: Props) { (file) => file.ownerID === user?.id ); const exportRecord = await exportService.getExportRecord(); - const exportedFileCnt = exportRecord.exportedFiles.length; - const failedFilesCnt = exportRecord.failedFiles.length; + const exportedFileCnt = exportRecord.exportedFiles?.length; + const failedFilesCnt = exportRecord.failedFiles?.length; const syncedFilesCnt = userPersonalFiles.length; if (syncedFilesCnt > exportedFileCnt + failedFilesCnt) { updateExportProgress({ @@ -191,8 +191,8 @@ export default function ExportModal(props: Props) { updateExportStage(ExportStage.INPROGRESS); await sleep(100); }; - const postExportRun = async (paused: Boolean) => { - if (!paused) { + const postExportRun = async (exportResult?: { paused?: boolean }) => { + if (!exportResult?.paused) { updateExportStage(ExportStage.FINISHED); await sleep(100); updateExportTime(Date.now()); @@ -202,22 +202,22 @@ export default function ExportModal(props: Props) { const startExport = async () => { await preExportRun(); updateExportProgress({ current: 0, total: 0 }); - const { paused } = await exportService.exportFiles( + const exportResult = await exportService.exportFiles( updateExportProgress, ExportType.NEW ); - await postExportRun(paused); + await postExportRun(exportResult); }; const stopExport = async () => { exportService.stopRunningExport(); - postExportRun(false); + postExportRun(); }; const pauseExport = () => { updateExportStage(ExportStage.PAUSED); exportService.pauseRunningExport(); - postExportRun(true); + postExportRun({ paused: true }); }; const resumeExport = async () => { @@ -232,23 +232,23 @@ export default function ExportModal(props: Props) { current: pausedStageProgress.current + progress.current, total: pausedStageProgress.current + progress.total, }); - const { paused } = await exportService.exportFiles( + const exportResult = await exportService.exportFiles( updateExportStatsWithOffset, ExportType.PENDING ); - await postExportRun(paused); + await postExportRun(exportResult); }; const retryFailedExport = async () => { await preExportRun(); updateExportProgress({ current: 0, total: exportStats.failed }); - const { paused } = await exportService.exportFiles( + const exportResult = await exportService.exportFiles( updateExportProgress, ExportType.RETRY_FAILED ); - await postExportRun(paused); + await postExportRun(exportResult); }; const syncExportStatsWithReport = async () => {