fix(ui): drop stale alert loads so badge and list agree
This commit is contained in:
1 parent
c00d4b330b
commit
ae7feb2d87
1 file changed
+9
-2
@@ -13,17 +13,24 @@ import type { OperatorAlert } from "./alerts";
|
||||
export function useAlerts() {
|
||||
const alerts = ref<OperatorAlert[]>([]);
|
||||
const failed = ref(false);
|
||||
// Loads overlap when alert events arrive close together; only the newest
|
||||
// may land, or an older list overwrites a newer one.
|
||||
let latest = 0;
|
||||
|
||||
async function load() {
|
||||
const seq = ++latest;
|
||||
try {
|
||||
alerts.value = (await api.alerts<{ alerts: OperatorAlert[] }>()).alerts;
|
||||
const next = (await api.alerts<{ alerts: OperatorAlert[] }>()).alerts;
|
||||
if (seq !== latest) return;
|
||||
alerts.value = next;
|
||||
failed.value = false;
|
||||
} catch {
|
||||
failed.value = true;
|
||||
if (seq === latest) failed.value = true;
|
||||
}
|
||||
}
|
||||
|
||||
async function dismiss(alert: OperatorAlert) {
|
||||
latest++;
|
||||
alerts.value = alerts.value.filter((a) => a.id !== alert.id);
|
||||
try {
|
||||
await api.dismissAlert(alert.id);
|
||||
|
||||
Reference in new issue
Block a user