Skip to content

Commit

Permalink
Fixed :web home page to refetch
Browse files Browse the repository at this point in the history
  • Loading branch information
retrodaredevil committed Mar 5, 2024
1 parent d4d365e commit a319278
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion web/src/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions web/src/timeUtil.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit a319278

Please sign in to comment.