From aad0e0bcde28e5bbe7247be19b1e60741663da41 Mon Sep 17 00:00:00 2001 From: Frank Gehann Date: Wed, 19 Aug 2026 15:10:33 +0200 Subject: [PATCH] fix(ui): update the dashboard in place instead of blanking it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Every 30 seconds the poll timer replaced what was on screen with a "loading" line before the new data arrived: the chart effect cleared its history, and the diagnostics view cleared its tables, on every run rather than only when the query changed. The chart then re-entered with its 500 ms animation. Taken together that reads as the page reloading itself twice a minute. Both views now keep what they show while the next payload is fetched, and only empty themselves when the range, inverter or period actually changes — where stale data would be wrong rather than merely old. The chart series animate on their first payload and swap values silently afterwards. A failed poll no longer empties anything either. The status cards keep the last reading and the header gains an offline badge, so a network hiccup costs a badge rather than the whole page. --- src/ui/src/App.tsx | 11 +++++-- src/ui/src/components/DiagnosticsView.tsx | 21 ++++++++++--- src/ui/src/components/HistoryChart.tsx | 38 ++++++++++++++++++++--- src/ui/src/components/ServiceStatus.tsx | 11 ++++++- 4 files changed, 69 insertions(+), 12 deletions(-) diff --git a/src/ui/src/App.tsx b/src/ui/src/App.tsx index 12ba375..ec81a04 100644 --- a/src/ui/src/App.tsx +++ b/src/ui/src/App.tsx @@ -35,8 +35,12 @@ export default function App() { // Kept in App so the choice survives leaving and re-entering the area. const [systemTab, setSystemTab] = useState("transmissions"); const [refreshKey, setRefreshKey] = useState(0); + // The last poll failed. The data stays on screen; only the badge changes. + const [offline, setOffline] = useState(false); - // Poll live status every 30 s. + // Poll live status every 30 s. The cards and charts update in place — a + // failed poll keeps the last reading on screen rather than emptying the + // page, which would flicker once every time the network hiccups. useEffect(() => { let active = true; const load = () => @@ -44,9 +48,10 @@ export default function App() { .then((s) => { if (!active) return; setStatus(s); + setOffline(false); setRefreshKey((value) => value + 1); }) - .catch(() => active && setStatus(null)); + .catch(() => active && setOffline(true)); load(); const timer = setInterval(load, 30_000); return () => { @@ -111,7 +116,7 @@ export default function App() { - + diff --git a/src/ui/src/components/DiagnosticsView.tsx b/src/ui/src/components/DiagnosticsView.tsx index a8a395e..4f988d9 100644 --- a/src/ui/src/components/DiagnosticsView.tsx +++ b/src/ui/src/components/DiagnosticsView.tsx @@ -1,4 +1,4 @@ -import { useEffect, useMemo, useState } from "react"; +import { useEffect, useMemo, useRef, useState } from "react"; import { Area, CartesianGrid, @@ -74,20 +74,33 @@ export function DiagnosticsView({ const { locale, t } = useI18n(); const [diagnostics, setDiagnostics] = useState(null); const [error, setError] = useState(null); + // What the tables on screen show. The 30-second refresh swaps their values; + // only a different day or inverter empties them, since keeping one + // inverter's rows under another's name would be wrong rather than merely + // stale. + const shownQuery = useRef(null); useEffect(() => { let cancelled = false; - setDiagnostics(null); + const query = `${date ?? ""}|${serial ?? "all"}`; + if (shownQuery.current !== query) { + setDiagnostics(null); + } setError(null); fetchDiagnostics(date, serial) - .then((data) => !cancelled && setDiagnostics(data)) + .then((data) => { + if (cancelled) return; + shownQuery.current = query; + setDiagnostics(data); + }) .catch((reason: unknown) => !cancelled && setError(String(reason))); return () => { cancelled = true; }; }, [date, serial, refreshKey]); - if (error) { + // A failed refresh keeps the tables that are already up. + if (error && !diagnostics) { return (

{t("loadError", { error })} diff --git a/src/ui/src/components/HistoryChart.tsx b/src/ui/src/components/HistoryChart.tsx index f76002f..6a1aaba 100644 --- a/src/ui/src/components/HistoryChart.tsx +++ b/src/ui/src/components/HistoryChart.tsx @@ -1,4 +1,4 @@ -import { type ReactNode, useEffect, useMemo, useState } from "react"; +import { type ReactNode, useEffect, useMemo, useRef, useState } from "react"; import { Area, Bar, @@ -93,10 +93,23 @@ export function HistoryChart({ const [year, setYear] = useState(null); const [currentYear, setCurrentYear] = useState(null); const [refresh, setRefresh] = useState(0); + // The chart animates when it first appears. A periodic refresh replaces the + // data of a chart that is already on screen, and replaying the animation + // there reads as flicker. + const [animate, setAnimate] = useState(true); + // What the data on screen belongs to. A refresh keeps it and swaps the + // values underneath; a different range, inverter or period does not, since + // showing one period's data under another's heading would be a lie. + const shownQuery = useRef(null); useEffect(() => { let cancelled = false; - setHistory(null); + const query = [range, serial ?? "all", day, week, month, year].join("|"); + const sameChart = shownQuery.current === query; + if (!sameChart) { + setHistory(null); + setAnimate(true); + } setError(null); const period = range === "day" @@ -111,7 +124,11 @@ export function HistoryChart({ fetchHistory(range, serial, false, period) .then((data) => { if (cancelled) return; + shownQuery.current = query; setHistory(data); + if (sameChart) { + setAnimate(false); + } if (range === "day" && data.date && day === null) { setDay(data.date); } @@ -154,7 +171,7 @@ export function HistoryChart({ const live = isDay && day !== null && day === today; let chart: ReactNode; - if (error) { + if (error && !history) { chart = (

{t("loadError", { error })} @@ -177,7 +194,13 @@ export function HistoryChart({ ); } else { if (isDay) { - chart = ; + chart = ( + + ); } else if (range === "week") { chart = ; } else if (range === "month") { @@ -248,6 +271,7 @@ export function HistoryChart({ dataKey={dataKey} fill={`var(--color-${dataKey})`} radius={[4, 4, 0, 0]} + isAnimationActive={animate} /> ))} @@ -310,9 +334,13 @@ export function HistoryChart({ function DayHistoryChart({ history, allInverters, + animate, }: { history: History; allInverters: boolean; + /// False once the chart is on screen and only its data is being replaced, + /// so a refresh does not replay the entry animation. + animate: boolean; }) { const { locale, t } = useI18n(); const availableSeries = useMemo( @@ -545,6 +573,7 @@ function DayHistoryChart({ activeDot={{ r: 3 }} connectNulls={false} hide={hiddenSeries.has(item.key)} + isAnimationActive={animate} animationDuration={500} /> ) : ( @@ -561,6 +590,7 @@ function DayHistoryChart({ dot={false} activeDot={{ r: 4, strokeWidth: 2 }} hide={hiddenSeries.has(item.key)} + isAnimationActive={animate} animationDuration={500} /> ), diff --git a/src/ui/src/components/ServiceStatus.tsx b/src/ui/src/components/ServiceStatus.tsx index cf076ca..9b9ddfa 100644 --- a/src/ui/src/components/ServiceStatus.tsx +++ b/src/ui/src/components/ServiceStatus.tsx @@ -12,7 +12,15 @@ import { } from "@/components/ui/popover"; import { useI18n } from "@/lib/i18n"; -export function ServiceStatus({ status }: { status: Status | null }) { +export function ServiceStatus({ + status, + offline = false, +}: { + status: Status | null; + /// The last poll did not reach the service. Its previous reading stays on + /// screen, so the badge is what says the numbers are no longer live. + offline?: boolean; +}) { const { t } = useI18n(); if (!status) { @@ -22,6 +30,7 @@ export function ServiceStatus({ status }: { status: Status | null }) { return (

v{status.version} + {offline && {t("offline")}} {status.lastError && (