From cfa6e70c13d251a75ac9d02545b8c036030005eb Mon Sep 17 00:00:00 2001 From: Nico Date: Thu, 4 Jun 2026 14:29:55 -0700 Subject: [PATCH] fix: unlock map controls after stale save --- frontend/src/hooks/useLocationMapDraftActions.js | 8 ++++---- frontend/src/hooks/useLocationMapDraftState.js | 2 ++ frontend/tests/location-map-manager.spec.ts | 2 ++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/frontend/src/hooks/useLocationMapDraftActions.js b/frontend/src/hooks/useLocationMapDraftActions.js index 22fa23a..57d5004 100644 --- a/frontend/src/hooks/useLocationMapDraftActions.js +++ b/frontend/src/hooks/useLocationMapDraftActions.js @@ -58,7 +58,7 @@ export default function useLocationMapDraftActions({ if (!isCurrentScope()) return; toast.error("Create map failed", getApiErrorMessage(error, "Failed to create map")); } finally { - endSaving(); + if (isCurrentScope()) endSaving(); } }, [ activeHouseholdId, applyDraftResponse, beginSaving, endSaving, isCurrentScope, @@ -78,7 +78,7 @@ export default function useLocationMapDraftActions({ if (!isCurrentScope()) return; toast.error("Create map failed", getApiErrorMessage(error, "Failed to create map from zones")); } finally { - endSaving(); + if (isCurrentScope()) endSaving(); } }, [ activeHouseholdId, applyDraftResponse, beginSaving, endSaving, isCurrentScope, @@ -100,7 +100,7 @@ export default function useLocationMapDraftActions({ if (!isCurrentScope()) return; toast.error("Save draft failed", getApiErrorMessage(error, "Failed to save map draft")); } finally { - endSaving(); + if (isCurrentScope()) endSaving(); } }, [ activeHouseholdId, applyDraftResponse, beginSaving, endSaving, isCurrentScope, locationId, @@ -137,7 +137,7 @@ export default function useLocationMapDraftActions({ const message = getApiErrorMessage(error, "Failed to publish map"); toast.error("Publish failed", savedPendingDraft ? `${message}. Draft changes were saved.` : message); } finally { - endSaving(); + if (isCurrentScope()) endSaving(); } }, [ activeHouseholdId, applyDraftResponse, beginSaving, endSaving, hasUnsavedChanges, isCurrentScope, diff --git a/frontend/src/hooks/useLocationMapDraftState.js b/frontend/src/hooks/useLocationMapDraftState.js index 8e9db4c..a73bb43 100644 --- a/frontend/src/hooks/useLocationMapDraftState.js +++ b/frontend/src/hooks/useLocationMapDraftState.js @@ -88,6 +88,8 @@ export default function useLocationMapDraftState({ setLoading(true); setLoadError(null); + setSaving(false); + setSavingAction(null); setFilters({ ...DEFAULT_MAP_FILTERS }); setLayersOpen(false); try { diff --git a/frontend/tests/location-map-manager.spec.ts b/frontend/tests/location-map-manager.spec.ts index c32fef2..d348bb5 100644 --- a/frontend/tests/location-map-manager.spec.ts +++ b/frontend/tests/location-map-manager.spec.ts @@ -702,12 +702,14 @@ test("ignores stale map save responses after switching locations", async ({ page await expect(page.getByRole("button", { name: "Map area Ontario Produce" })).toBeVisible(); await expect(page.locator(".location-map-title span")).toHaveText("Ontario"); + await expect(page.getByRole("button", { name: "Edit Draft" })).toBeEnabled(); releaseSaveResponse(); await saveResponded; await expect(page.getByRole("button", { name: "Map area Ontario Produce" })).toBeVisible(); await expect(page.locator(".location-map-title span")).toHaveText("Ontario"); + await expect(page.getByRole("button", { name: "Edit Draft" })).toBeEnabled(); await expect(page.getByRole("button", { name: "Map area Saved Eastvale Bakery" })).toHaveCount(0); await expect(page.getByText("Saved draft")).toHaveCount(0); });