From 2374bad7baf54f5f4f871d8be1bff7db5404940a Mon Sep 17 00:00:00 2001 From: Josh Wright Date: Sun, 12 Apr 2026 12:04:21 -0400 Subject: [PATCH] Sync open alert count in localStorage on status toggle After closing or reopening an alert, patch the cached dashboard stats in localStorage so the summary card and tab badge reflect the new count immediately when navigating back, without waiting for a refresh. Co-Authored-By: Claude Sonnet 4.6 --- src/app/alerts/[id]/AlertDetail.tsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/app/alerts/[id]/AlertDetail.tsx b/src/app/alerts/[id]/AlertDetail.tsx index 4476ab1..ef9dbe5 100644 --- a/src/app/alerts/[id]/AlertDetail.tsx +++ b/src/app/alerts/[id]/AlertDetail.tsx @@ -127,7 +127,20 @@ export default function AlertDetail({ initialAlert }: { initialAlert: Alert }) { body: JSON.stringify({ status: newStatus }), }); if (!res.ok) throw new Error(`HTTP ${res.status}`); - setAlert(await res.json()); + const updated: Alert = await res.json(); + setAlert(updated); + + // Keep the cached dashboard count in sync so the badge and summary + // card reflect the change immediately when navigating back. + try { + const raw = localStorage.getItem("oversnitch_stats"); + if (raw) { + const stats = JSON.parse(raw); + const delta = updated.status === "open" ? 1 : -1; + stats.summary.openAlertCount = Math.max(0, (stats.summary.openAlertCount ?? 0) + delta); + localStorage.setItem("oversnitch_stats", JSON.stringify(stats)); + } + } catch {} } catch (e) { setError(e instanceof Error ? e.message : String(e)); } finally {