|
1 | 1 | import { createFileRoute } from "@tanstack/react-router"; |
2 | | -import { useEffect, useState } from "react"; |
| 2 | +import { useState } from "react"; |
3 | 3 | import { Bar, BarChart, Cell, XAxis, YAxis } from "recharts"; |
4 | 4 |
|
5 | 5 | import { Button } from "@loopover/ui-kit/components/button"; |
@@ -28,6 +28,7 @@ import { |
28 | 28 | type LedgersSummary, |
29 | 29 | } from "../lib/ledgers"; |
30 | 30 | import { fetchGovernorPauseState, pauseGovernor, resumeGovernor, type GovernorPauseStateResult } from "../lib/governor"; |
| 31 | +import { DEFAULT_POLL_INTERVAL_MS, usePolledFetch } from "../lib/use-polled-fetch"; |
31 | 32 |
|
32 | 33 | export const Route = createFileRoute("/ledgers")({ |
33 | 34 | component: LedgersPage, |
@@ -407,35 +408,30 @@ export function LedgersPage({ |
407 | 408 | loadGovernorPauseState = fetchGovernorPauseState, |
408 | 409 | pauseGovernorAction = pauseGovernor, |
409 | 410 | resumeGovernorAction = resumeGovernor, |
| 411 | + pollIntervalMs = DEFAULT_POLL_INTERVAL_MS, |
410 | 412 | }: { |
411 | 413 | loadLedgers?: () => Promise<LedgersResult>; |
412 | 414 | loadGovernorPauseState?: () => Promise<GovernorPauseStateResult>; |
413 | 415 | pauseGovernorAction?: (reason?: string) => Promise<GovernorPauseStateResult>; |
414 | 416 | resumeGovernorAction?: () => Promise<GovernorPauseStateResult>; |
| 417 | + pollIntervalMs?: number; |
415 | 418 | }) { |
416 | | - const [result, setResult] = useState<LedgersResult | null>(null); |
417 | 419 | const [pauseState, setPauseState] = useState<GovernorPauseStateResult | null>(null); |
| 420 | + const [lastPolledPauseState, setLastPolledPauseState] = useState<GovernorPauseStateResult | null>(null); |
418 | 421 | const [actionPending, setActionPending] = useState(false); |
419 | 422 |
|
420 | | - useEffect(() => { |
421 | | - let cancelled = false; |
422 | | - void loadLedgers().then((loaded) => { |
423 | | - if (!cancelled) setResult(loaded); |
424 | | - }); |
425 | | - return () => { |
426 | | - cancelled = true; |
427 | | - }; |
428 | | - }, [loadLedgers]); |
| 423 | + // Join the app's shared live-refresh cadence so newly-recorded claims/events appear without a manual reload, |
| 424 | + // matching the Overview page's claims card that reads the same data source (#7082). |
| 425 | + const result = usePolledFetch(loadLedgers, pollIntervalMs); |
429 | 426 |
|
430 | | - useEffect(() => { |
431 | | - let cancelled = false; |
432 | | - void loadGovernorPauseState().then((loaded) => { |
433 | | - if (!cancelled) setPauseState(loaded); |
434 | | - }); |
435 | | - return () => { |
436 | | - cancelled = true; |
437 | | - }; |
438 | | - }, [loadGovernorPauseState]); |
| 427 | + // Poll the governor pause-state on the same cadence. Each fresh poll result is synced into `pauseState` during |
| 428 | + // render, while the operator's own pause/resume action writes `pauseState` directly so it reflects immediately, |
| 429 | + // not only on the next tick (#7082). |
| 430 | + const polledPauseState = usePolledFetch(loadGovernorPauseState, pollIntervalMs); |
| 431 | + if (polledPauseState !== lastPolledPauseState) { |
| 432 | + setLastPolledPauseState(polledPauseState); |
| 433 | + setPauseState(polledPauseState); |
| 434 | + } |
439 | 435 |
|
440 | 436 | const runGovernorAction = (action: () => Promise<GovernorPauseStateResult>) => { |
441 | 437 | setActionPending(true); |
|
0 commit comments