fix(parcel-sync): progress display stuck + numbers jumping during sync

2 bugs:
1. After Magic/base download completes, progress bar stayed stuck at
   77% because exportProgress was never updated to 'done' client-side.
   Fix: set progress to 'Finalizat' + 100% after successful blob download.

2. syncLayer overwrote the export route's weighted percentages (0-100)
   with raw feature counts (50/200), causing progress bar to jump.
   Fix: when isSubStep=true, sync writes phase/note/phaseCurrent/phaseTotal
   but preserves the parent route's downloaded/total weighted values.
This commit is contained in:
AI Assistant
2026-03-07 11:45:52 +02:00
parent 097d010b5d
commit de1e779770
2 changed files with 56 additions and 1 deletions
@@ -579,6 +579,21 @@ export function ParcelSyncModule() {
a.click();
a.remove();
URL.revokeObjectURL(url);
// Mark progress as done after successful download
setExportProgress((prev) =>
prev
? {
...prev,
status: "done",
phase: "Finalizat",
downloaded: prev.total ?? 100,
total: prev.total ?? 100,
message: `Descărcare completă — ${filename}`,
note: undefined,
}
: null,
);
} catch (error) {
const msg = error instanceof Error ? error.message : "Eroare export";
setExportProgress((prev) =>
@@ -863,6 +878,21 @@ export function ParcelSyncModule() {
a.click();
a.remove();
URL.revokeObjectURL(url);
// Mark progress as done after successful download
setExportProgress((prev) =>
prev
? {
...prev,
status: "done",
phase: "Finalizat",
downloaded: prev.total ?? 100,
total: prev.total ?? 100,
message: `Descărcare completă — ${filename}`,
note: undefined,
}
: null,
);
} catch (error) {
const msg = error instanceof Error ? error.message : "Eroare export";
setExportProgress((prev) =>
@@ -13,6 +13,7 @@ import { findLayerById, type LayerCatalogItem } from "./eterra-layers";
import { fetchUatGeometry } from "./uat-geometry";
import {
setProgress,
getProgress,
clearProgress,
type SyncProgress,
} from "./progress-store";
@@ -62,6 +63,26 @@ export async function syncLayer(
const push = (partial: Partial<SyncProgress>) => {
if (!jobId) return;
if (isSubStep) {
// When running as sub-step of a larger export, only write
// phase/note/phaseCurrent/phaseTotal — preserve the parent's
// downloaded/total weighted percentages.
const existing = getProgress(jobId);
setProgress({
jobId,
downloaded: existing?.downloaded ?? 0,
total: existing?.total,
status: "running",
...existing,
// Only overwrite informational fields
phase: partial.phase ?? existing?.phase,
note: partial.note,
phaseCurrent: partial.downloaded, // map sync's downloaded → sub-detail
phaseTotal: partial.total, // map sync's total → sub-detail
message: partial.message,
} as SyncProgress);
return;
}
setProgress({
jobId,
downloaded: 0,
@@ -287,7 +308,11 @@ export async function syncLayer(
where: { id: syncRun.id },
data: { status: "error", errorMessage: msg, completedAt: new Date() },
});
push({ phase: "Eroare sync", status: isSubStep ? "running" : "error", message: msg });
push({
phase: "Eroare sync",
status: isSubStep ? "running" : "error",
message: msg,
});
if (jobId && !isSubStep) setTimeout(() => clearProgress(jobId), 60_000);
return {
layerId,