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 <noreply@anthropic.com>
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user