mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 05:18:11 +00:00
implement batch board notification system for schedule changes and updates
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user