implement batch board notification system for schedule changes and updates

This commit is contained in:
Marshal
2026-07-12 12:01:05 +00:00
parent 4b7f6d2548
commit 84ba56f7d0
10 changed files with 195 additions and 32 deletions

View File

@@ -1,6 +1,7 @@
import {
BOOKING_WINDOW_WS_EVENTS,
BOOKING_WINDOW_WS_NAMESPACE,
type BatchBoardChangedEvent,
type BookingWindowPhaseEvent,
} from "@edr/types";
import { useQueryClient } from "@tanstack/react-query";
@@ -82,9 +83,19 @@ export function useBookingWindowSocket(enabled: boolean = true) {
// Deliberate console breadcrumbs: "live updates not arriving" is only
// diagnosable from the browser when connect/reject outcomes are visible.
socket.on("connect", () =>
console.debug("[booking-windows] socket connected", socket.id),
);
let hadConnected = false;
socket.on("connect", () => {
console.debug("[booking-windows] socket connected", socket.id);
// A RE-connect means pushes may have been missed while offline — refetch
// every board view (list + any open detail share the "batch-board" key
// prefix) once so the gap self-heals immediately.
if (hadConnected) {
void qc.invalidateQueries({
queryKey: ["train-scheduling", "batch-board"],
});
}
hadConnected = true;
});
socket.on("connect_error", (err) =>
console.warn("[booking-windows] socket connect failed:", err.message),
);
@@ -144,6 +155,19 @@ export function useBookingWindowSocket(enabled: boolean = true) {
},
);
// Board-data pushes (payment settled, allocation, fill, expiry, …): refetch
// the schedule's detail immediately, refresh the list debounced. The event
// carries no data — the board views are rich, differently-shaped queries.
socket.on(
BOOKING_WINDOW_WS_EVENTS.BATCH_CHANGED,
(event: BatchBoardChangedEvent) => {
void qc.invalidateQueries({
queryKey: QUERY_KEYS.TRAIN_SCHEDULING.batchBoardDetail(event.scheduleId),
});
scheduleRefetch(false);
},
);
return () => {
if (refetchTimer) clearTimeout(refetchTimer);
socket.off();