diff --git a/web/src/pages/Home.tsx b/web/src/pages/Home.tsx index 5eafea31..5608400d 100644 --- a/web/src/pages/Home.tsx +++ b/web/src/pages/Home.tsx @@ -10,7 +10,15 @@ function BatteryVoltage() { const [sourceId] = useSourceId(); // We have to use a rounded up value to make sure that useQuery doesn't keep reloading the data const timeMillisRounded = getTimeMillisRounded(); - const {data, error, isLoading, isSuccess} = useHomeQuery(graphQLClient, { sourceId, currentTimeMillis: "" + timeMillisRounded}); + const {data, error, isLoading, isSuccess} = useHomeQuery( + graphQLClient, + { + sourceId, currentTimeMillis: "" + timeMillisRounded + }, + { + refetchInterval: 10_000 + } + ); const averageNode = data === undefined ? undefined : data!.queryStatusLast.batteryVoltageAverage[0]; return <> {!isSuccess diff --git a/web/src/timeUtil.ts b/web/src/timeUtil.ts index bfd14fe1..42820cf7 100644 --- a/web/src/timeUtil.ts +++ b/web/src/timeUtil.ts @@ -1,6 +1,9 @@ export function getTimeMillisRounded() { + // NOTE: When we use this, it's a little bit hacky. + // First off, we still have to explicitly tell our client to have a refetch interval because this is not a hook. + // Second off, if that fetch takes longer than 10 seconds, this will update in that time, causing an immediate refetch. const currentTimeMillis = Date.now(); return Math.ceil(currentTimeMillis / 10_000) * 10_000; }