Skip to content

Commit 23e1f71

Browse files
committed
fix: fix blank tracker map
1 parent 4597b1d commit 23e1f71

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

apps/client/src/Components/Molecules/DataLora/useLocQuery.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { TrackerItem, TrackerQueryType } from "@homeremote/types";
2-
import { useState } from "react";
2+
import { useEffect, useState } from "react";
33
import { useGetCoordsQuery } from "../../../Services/dataloraApi";
4+
import { getErrorMessage } from "../../../Utils/getErrorMessage";
5+
import { useAppDispatch } from "../../../store";
6+
import { logInfo } from "../LogCard/logSlice";
47

58
const UPDATE_INTERVAL_MS = 1000 * 60 * 60; // 1000 ms / 60 seconds / 60 minutes = 1x per hour
69

@@ -13,19 +16,37 @@ interface LocQuery {
1316
}
1417

1518
export const useLocQuery = (): LocQuery => {
19+
const dispatch = useAppDispatch();
20+
1621
const [queryType, setQueryType] = useState<TrackerQueryType>("24h");
1722
const {
1823
data: coords,
1924
isLoading,
2025
isFetching,
2126
refetch,
27+
isError,
28+
error,
2229
} = useGetCoordsQuery(
2330
{
2431
type: queryType,
2532
},
2633
{ pollingInterval: UPDATE_INTERVAL_MS, refetchOnMountOrArgChange: true }
2734
);
2835

36+
useEffect(() => {
37+
if (isError && error) {
38+
// This errors to often to use logError
39+
dispatch(logInfo(`useLocQuery failed: ${getErrorMessage(error)}`));
40+
}
41+
}, [dispatch, error, isError]);
42+
43+
// There often is an error on the first call, so retry after 5 seconds (also if there is no error)
44+
useEffect(() => {
45+
setTimeout(() => {
46+
refetch();
47+
}, 5000);
48+
}, [refetch]);
49+
2950
const update = async (): Promise<void> => {
3051
refetch();
3152
};
@@ -36,7 +57,7 @@ export const useLocQuery = (): LocQuery => {
3657
};
3758

3859
return {
39-
coords: coords ?? [],
60+
coords: coords ?? [[], []],
4061
update,
4162
isLoading: isLoading || isFetching,
4263
toggleQueryType,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "homeremote",
3-
"version": "3.7.11",
3+
"version": "3.7.12",
44
"license": "MIT",
55
"scripts": {
66
"writeGitInfo": "ts-node --project ./tsconfig.node.json writeGitInfo.ts",

0 commit comments

Comments
 (0)