minor fixes
This commit is contained in:
parent
acb1975cdc
commit
8a83254978
|
@ -3,6 +3,7 @@ import React, { useEffect, useState } from 'react';
|
||||||
import { Button } from 'react-bootstrap';
|
import { Button } from 'react-bootstrap';
|
||||||
import exportService, { ExportRecord, ExportStage, ExportStats } from 'services/exportService';
|
import exportService, { ExportRecord, ExportStage, ExportStats } from 'services/exportService';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
|
import { sleep } from 'utils/common';
|
||||||
import { getData, LS_KEYS, setData } from 'utils/storage/localStorage';
|
import { getData, LS_KEYS, setData } from 'utils/storage/localStorage';
|
||||||
import constants from 'utils/strings/constants';
|
import constants from 'utils/strings/constants';
|
||||||
import { Label, Row, Value } from './Container';
|
import { Label, Row, Value } from './Container';
|
||||||
|
@ -97,6 +98,7 @@ export default function ExportModal(props: Props) {
|
||||||
updateExportStats({ current: 0, total: 0, failed: 0 });
|
updateExportStats({ current: 0, total: 0, failed: 0 });
|
||||||
await exportService.exportFiles(updateExportStats);
|
await exportService.exportFiles(updateExportStats);
|
||||||
updateExportStage(ExportStage.FINISHED);
|
updateExportStage(ExportStage.FINISHED);
|
||||||
|
await sleep(100);
|
||||||
updateExportTime(Date.now());
|
updateExportTime(Date.now());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -133,8 +135,12 @@ export default function ExportModal(props: Props) {
|
||||||
};
|
};
|
||||||
const retryFailed = async () => {
|
const retryFailed = async () => {
|
||||||
updateExportStage(ExportStage.INPROGRESS);
|
updateExportStage(ExportStage.INPROGRESS);
|
||||||
|
await sleep(100);
|
||||||
updateExportStats({ current: 0, total: exportStats.failed, failed: 0 });
|
updateExportStats({ current: 0, total: exportStats.failed, failed: 0 });
|
||||||
exportService.retryFailedFiles(updateExportStats);
|
await exportService.retryFailedFiles(updateExportStats);
|
||||||
|
updateExportStage(ExportStage.FINISHED);
|
||||||
|
await sleep(100);
|
||||||
|
updateExportTime(Date.now());
|
||||||
};
|
};
|
||||||
|
|
||||||
const ExportDynamicState = () => {
|
const ExportDynamicState = () => {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { retryPromise, runningInBrowser, sleep } from 'utils/common';
|
import { retryPromise, runningInBrowser } from 'utils/common';
|
||||||
import { logError } from 'utils/sentry';
|
import { logError } from 'utils/sentry';
|
||||||
import { getData, LS_KEYS } from 'utils/storage/localStorage';
|
import { getData, LS_KEYS } from 'utils/storage/localStorage';
|
||||||
import { Collection, getLocalCollections } from './collectionService';
|
import { Collection, getLocalCollections } from './collectionService';
|
||||||
|
@ -43,7 +43,7 @@ class ExportService {
|
||||||
ElectronAPIs: any;
|
ElectronAPIs: any;
|
||||||
|
|
||||||
private exportInProgress: Promise<void> = null;
|
private exportInProgress: Promise<void> = null;
|
||||||
private recordUpdateInProgress: Promise<void> = null;
|
private recordUpdateInProgress: Promise<void> = Promise.resolve();
|
||||||
private stopExport: boolean = false;
|
private stopExport: boolean = false;
|
||||||
private pauseExport: boolean = false;
|
private pauseExport: boolean = false;
|
||||||
|
|
||||||
|
@ -196,22 +196,24 @@ class ExportService {
|
||||||
exportRecord.exportedFiles = [];
|
exportRecord.exportedFiles = [];
|
||||||
}
|
}
|
||||||
exportRecord.exportedFiles.push(fileUID);
|
exportRecord.exportedFiles.push(fileUID);
|
||||||
|
exportRecord.failedFiles = exportRecord.failedFiles.filter((FailedFileUID) => FailedFileUID !== fileUID);
|
||||||
} else {
|
} else {
|
||||||
if (!exportRecord.failedFiles) {
|
if (!exportRecord.failedFiles) {
|
||||||
exportRecord.failedFiles = [];
|
exportRecord.failedFiles = [];
|
||||||
}
|
}
|
||||||
|
if (!exportRecord.failedFiles.find((x) => x === fileUID)) {
|
||||||
exportRecord.failedFiles.push(fileUID);
|
exportRecord.failedFiles.push(fileUID);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
await this.updateExportRecord(exportRecord, folder);
|
await this.updateExportRecord(exportRecord, folder);
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateExportRecord(newData: Record<string, any>, folder?: string) {
|
async updateExportRecordSync(newData: Record<string, any>, folder?: string) {
|
||||||
await sleep(100);
|
this.recordUpdateInProgress = this.updateExportRecord(newData, folder);
|
||||||
if (this.recordUpdateInProgress) {
|
|
||||||
await this.recordUpdateInProgress;
|
|
||||||
this.recordUpdateInProgress = null;
|
|
||||||
}
|
}
|
||||||
this.recordUpdateInProgress = (async () => {
|
async updateExportRecord(newData: Record<string, any>, folder?: string) {
|
||||||
|
await this.recordUpdateInProgress;
|
||||||
|
try {
|
||||||
if (!folder) {
|
if (!folder) {
|
||||||
folder = getData(LS_KEYS.EXPORT_FOLDER);
|
folder = getData(LS_KEYS.EXPORT_FOLDER);
|
||||||
}
|
}
|
||||||
|
@ -219,11 +221,13 @@ class ExportService {
|
||||||
const newRecord = { ...exportRecord, ...newData };
|
const newRecord = { ...exportRecord, ...newData };
|
||||||
console.log(newRecord, JSON.stringify(newRecord, null, 2));
|
console.log(newRecord, JSON.stringify(newRecord, null, 2));
|
||||||
await this.ElectronAPIs.setExportRecord(folder, JSON.stringify(newRecord, null, 2));
|
await this.ElectronAPIs.setExportRecord(folder, JSON.stringify(newRecord, null, 2));
|
||||||
})();
|
} catch (e) {
|
||||||
await this.recordUpdateInProgress;
|
console.log(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getExportRecord(folder?: string): Promise<ExportRecord> {
|
async getExportRecord(folder?: string): Promise<ExportRecord> {
|
||||||
|
try {
|
||||||
console.log(folder);
|
console.log(folder);
|
||||||
if (!folder) {
|
if (!folder) {
|
||||||
folder = getData(LS_KEYS.EXPORT_FOLDER);
|
folder = getData(LS_KEYS.EXPORT_FOLDER);
|
||||||
|
@ -232,6 +236,9 @@ class ExportService {
|
||||||
if (recordFile) {
|
if (recordFile) {
|
||||||
return JSON.parse(recordFile);
|
return JSON.parse(recordFile);
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async downloadAndSave(file: File, path) {
|
async downloadAndSave(file: File, path) {
|
||||||
|
|
Loading…
Reference in a new issue