Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

fix(Export):resolve export loader stuck issue

Aswin Asokf84d530f5c0f
diff --git a/web/packages/new/photos/components/Export.tsx b/web/packages/new/photos/components/Export.tsx
index 0cfb77a3bf..0d14aac739 100644
--- a/web/packages/new/photos/components/Export.tsx
+++ b/web/packages/new/photos/components/Export.tsx
@@ -96,7 +96,13 @@ export const Export: React.FC<ExportProps> = ({
}
const exportRecord =
await exportService.getExportRecord(exportFolder);
- setExportStage(exportRecord.stage);
+ const currentStage = exportService.getCurrentExportStage();
+ const isRunning = Boolean(exportService.isExportInProgress());
+ const effectiveStage =
+ isRunning && currentStage !== ExportStage.init
+ ? currentStage
+ : exportRecord.stage;
+ setExportStage(effectiveStage);
setLastExportTime(exportRecord.lastAttemptTimestamp);
setPendingFiles(await exportService.pendingFiles(exportRecord));
} catch (e) {
@@ -130,20 +136,6 @@ export const Export: React.FC<ExportProps> = ({
void syncExportRecord(exportFolder);
}, [open, exportFolder, syncExportRecord]);
- useEffect(() => {
- if (!exportService.isExportInProgress()) return;
-
- // If the dialog mounts mid-export, the stage can lag behind progress.
- const processed = exportProgress.success + exportProgress.failed;
- if (
- exportStage < ExportStage.exportingFiles &&
- exportProgress.total > 0 &&
- processed > 0
- ) {
- setExportStage(ExportStage.exportingFiles);
- }
- }, [exportProgress, exportStage, exportService]);
-
const verifyExportFolderExists = useCallback(async () => {
if (!(await exportService.exportFolderExists(exportFolder))) {
showMiniDialog({
diff --git a/web/packages/new/photos/services/export.ts b/web/packages/new/photos/services/export.ts
index 0659797bf3..74c436b4df 100644
--- a/web/packages/new/photos/services/export.ts
+++ b/web/packages/new/photos/services/export.ts
@@ -189,6 +189,7 @@ class ExportService {
success: 0,
failed: 0,
};
+ private currentExportStage: ExportStage = ExportStage.init;
// @ts-ignore
private cachedMetadataDateTimeFormatter: Intl.DateTimeFormat;
@@ -221,6 +222,7 @@ class ExportService {
setUIUpdaters(uiUpdater: ExportUIUpdaters) {
this.uiUpdater = uiUpdater;
this.uiUpdater.setExportProgress(this.currentExportProgress);
+ this.uiUpdater.setExportStage(this.currentExportStage);
}
private updateExportProgress(exportProgress: ExportProgress) {
@@ -233,6 +235,7 @@ class ExportService {
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
const exportFolder = this.getExportSettings()?.folder!;
await this.updateExportRecord(exportFolder, { stage });
+ this.currentExportStage = stage;
this.uiUpdater.setExportStage(stage);
}
@@ -318,6 +321,7 @@ class ExportService {
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
const exportFolder = this.getExportSettings()?.folder!;
if (!(await this.exportFolderExists(exportFolder))) {
+ this.currentExportStage = ExportStage.init;
this.uiUpdater.setExportStage(ExportStage.init);
return;
}
@@ -453,7 +457,7 @@ class ExportService {
);
let success = 0;
let failed = 0;
- this.uiUpdater.setExportProgress({
+ this.updateExportProgress({
success: success,
failed: failed,
total: filesToExport.length,
@@ -900,11 +904,11 @@ class ExportService {
if (!exportRecord.fileExportNames) {
exportRecord.fileExportNames = {};
}
- exportRecord.fileExportNames = {
+ const fileExportNames = {
...exportRecord.fileExportNames,
[fileUID]: fileExportName,
};
- await this.updateExportRecord(folder, exportRecord);
+ await this.updateExportRecord(folder, { fileExportNames });
} catch (e) {
// @ts-ignore
if (e.message !== CustomError.EXPORT_FOLDER_DOES_NOT_EXIST) {
@@ -924,12 +928,12 @@ class ExportService {
if (!exportRecord?.collectionExportNames) {
exportRecord.collectionExportNames = {};
}
- exportRecord.collectionExportNames = {
+ const collectionExportNames = {
...exportRecord.collectionExportNames,
[collectionID]: collectionExportName,
};
- await this.updateExportRecord(folder, exportRecord);
+ await this.updateExportRecord(folder, { collectionExportNames });
} catch (e) {
// @ts-ignore
if (e.message !== CustomError.EXPORT_FOLDER_DOES_NOT_EXIST) {
@@ -943,13 +947,13 @@ class ExportService {
try {
const exportRecord = await this.getExportRecord(folder);
- exportRecord.collectionExportNames = Object.fromEntries(
+ const collectionExportNames = Object.fromEntries(
Object.entries(exportRecord.collectionExportNames).filter(
([key]) => key !== collectionID.toString(),
),
);
- await this.updateExportRecord(folder, exportRecord);
+ await this.updateExportRecord(folder, { collectionExportNames });
} catch (e) {
// @ts-ignore
if (e.message !== CustomError.EXPORT_FOLDER_DOES_NOT_EXIST) {
@@ -962,12 +966,12 @@ class ExportService {
async removeFileExportedRecord(folder: string, fileUID: string) {
try {
const exportRecord = await this.getExportRecord(folder);
- exportRecord.fileExportNames = Object.fromEntries(
+ const fileExportNames = Object.fromEntries(
Object.entries(exportRecord.fileExportNames).filter(
([key]) => key !== fileUID,
),
);
- await this.updateExportRecord(folder, exportRecord);
+ await this.updateExportRecord(folder, { fileExportNames });
} catch (e) {
// @ts-ignore
if (e.message !== CustomError.EXPORT_FOLDER_DOES_NOT_EXIST) {
@@ -1203,6 +1207,10 @@ class ExportService {
return this.exportInProgress;
};
+ getCurrentExportStage = () => {
+ return this.currentExportStage;
+ };
+
exportFolderExists = async (exportFolder: string | undefined) => {
return exportFolder && (await ensureElectron().fs.exists(exportFolder));
};