mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-04 11:07:40 +01:00
fix(control): fleet state refreshes on cockpit:refresh
useControlData polls /api/control every 30s and on visibilitychange but ignored the cockpit:refresh broadcast — so PullToRefresh on /control or a tab-focus return via RefreshOnFocus refreshed everything *except* the fleet view that the page is actually about. Add a window listener for COCKPIT_REFRESH_EVENT that calls the same poll() the interval uses. inFlight guard already prevents duplicate requests when multiple triggers fire close together (PTR + visibility on the same gesture). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 file changed
+7
@@ -7,6 +7,7 @@ import type { OrchestrationTaskIntentId } from "@/lib/orchestration";
|
||||
import { getJson, postJson, throwApiError } from "@/lib/api/fetch";
|
||||
import { queueKey } from "@/lib/control-storage";
|
||||
import type { Agent } from "@/lib/agent-registry";
|
||||
import { COCKPIT_REFRESH_EVENT } from "@/lib/client-events";
|
||||
type AgentEntry = ControlData["agentRegistry"]["agents"][number];
|
||||
type TabResult = { status: string; tab?: string; reason?: string; error?: string };
|
||||
export interface ControlDataHook {
|
||||
@@ -94,10 +95,16 @@ export function useControlData(): ControlDataHook {
|
||||
|
||||
const onVisibilityChange = () => { if (!document.hidden) poll(); };
|
||||
document.addEventListener("visibilitychange", onVisibilityChange);
|
||||
// Listen for global refresh (PullToRefresh, RefreshOnFocus) so fleet state
|
||||
// catches up at the same moment server-component data and other useFetch
|
||||
// polls do — without waiting for the 30s tick.
|
||||
const onCockpitRefresh = () => { poll(); };
|
||||
window.addEventListener(COCKPIT_REFRESH_EVENT, onCockpitRefresh);
|
||||
const id = setInterval(poll, 30_000);
|
||||
return () => {
|
||||
clearInterval(id);
|
||||
document.removeEventListener("visibilitychange", onVisibilityChange);
|
||||
window.removeEventListener(COCKPIT_REFRESH_EVENT, onCockpitRefresh);
|
||||
};
|
||||
}, [refresh]);
|
||||
|
||||
|
||||
Reference in new issue
Block a user