@adventurelabs/scout-core 1.0.93 → 1.0.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useAppDispatch } from "../store/hooks";
|
|
3
3
|
import { useSelector } from "react-redux";
|
|
4
|
-
import { useEffect, useRef, useCallback
|
|
4
|
+
import { useEffect, useRef, useCallback } from "react";
|
|
5
5
|
import { setActiveHerdGpsTrackersConnectivity } from "../store/scout";
|
|
6
6
|
import { server_get_connectivity_by_device_id } from "../helpers/connectivity";
|
|
7
7
|
import { EnumWebResponse } from "../types/requests";
|
|
@@ -9,7 +9,6 @@ import { getDaysAgoTimestamp } from "../helpers/time";
|
|
|
9
9
|
export function useScoutRealtimeConnectivity(scoutSupabase) {
|
|
10
10
|
const channels = useRef([]);
|
|
11
11
|
const dispatch = useAppDispatch();
|
|
12
|
-
const [hasInitialized, setHasInitialized] = useState(null);
|
|
13
12
|
const activeHerdId = useSelector((state) => state.scout.active_herd_id);
|
|
14
13
|
const connectivity = useSelector((state) => state.scout.active_herd_gps_trackers_connectivity);
|
|
15
14
|
const herdModules = useSelector((state) => state.scout.herd_modules);
|
|
@@ -54,11 +53,12 @@ export function useScoutRealtimeConnectivity(scoutSupabase) {
|
|
|
54
53
|
}
|
|
55
54
|
break;
|
|
56
55
|
}
|
|
56
|
+
console.log("[Connectivity] updating tracker connectivity in response to broadcast");
|
|
57
57
|
dispatch(setActiveHerdGpsTrackersConnectivity(updatedConnectivity));
|
|
58
|
-
}, [connectivity
|
|
58
|
+
}, [connectivity]);
|
|
59
59
|
// Fetch initial connectivity data
|
|
60
60
|
const fetchInitialData = useCallback(async () => {
|
|
61
|
-
if (!activeHerdId
|
|
61
|
+
if (!activeHerdId)
|
|
62
62
|
return;
|
|
63
63
|
const herdId = activeHerdId; // Type narrowing
|
|
64
64
|
const activeHerdModule = herdModules.find((hm) => hm.herd.id.toString() === herdId);
|
|
@@ -67,7 +67,6 @@ export function useScoutRealtimeConnectivity(scoutSupabase) {
|
|
|
67
67
|
const gpsDevices = activeHerdModule.devices.filter((device) => device.device_type &&
|
|
68
68
|
["gps_tracker", "gps_tracker_vehicle", "gps_tracker_person"].includes(device.device_type));
|
|
69
69
|
if (gpsDevices.length === 0) {
|
|
70
|
-
setHasInitialized(herdId);
|
|
71
70
|
return;
|
|
72
71
|
}
|
|
73
72
|
console.log(`[Connectivity] Loading data for ${gpsDevices.length} GPS trackers`);
|
|
@@ -96,17 +95,14 @@ export function useScoutRealtimeConnectivity(scoutSupabase) {
|
|
|
96
95
|
}
|
|
97
96
|
}));
|
|
98
97
|
dispatch(setActiveHerdGpsTrackersConnectivity(connectivityData));
|
|
99
|
-
setHasInitialized(herdId);
|
|
100
98
|
console.log(`[Connectivity] Loaded data for ${Object.keys(connectivityData).length} devices`);
|
|
101
|
-
}, [activeHerdId, herdModules
|
|
99
|
+
}, [activeHerdId, herdModules]);
|
|
102
100
|
useEffect(() => {
|
|
103
|
-
if (!scoutSupabase || !activeHerdId)
|
|
101
|
+
if (!scoutSupabase || !activeHerdId || herdModules.length == 0)
|
|
104
102
|
return;
|
|
105
103
|
// Clean up existing channels
|
|
106
104
|
channels.current.forEach((channel) => scoutSupabase.removeChannel(channel));
|
|
107
105
|
channels.current = [];
|
|
108
|
-
// Reset initialization when herd changes
|
|
109
|
-
setHasInitialized(null);
|
|
110
106
|
// Create connectivity channel
|
|
111
107
|
const channel = scoutSupabase
|
|
112
108
|
.channel(`${activeHerdId}-connectivity`, { config: { private: true } })
|
|
@@ -126,10 +122,5 @@ export function useScoutRealtimeConnectivity(scoutSupabase) {
|
|
|
126
122
|
channels.current.forEach((ch) => scoutSupabase.removeChannel(ch));
|
|
127
123
|
channels.current = [];
|
|
128
124
|
};
|
|
129
|
-
}, [
|
|
130
|
-
scoutSupabase,
|
|
131
|
-
activeHerdId,
|
|
132
|
-
handleConnectivityBroadcast,
|
|
133
|
-
fetchInitialData,
|
|
134
|
-
]);
|
|
125
|
+
}, [activeHerdId, herdModules]);
|
|
135
126
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useEffect, useCallback, useRef } from "react";
|
|
2
2
|
import { useAppDispatch } from "../store/hooks";
|
|
3
|
-
import { EnumScoutStateStatus,
|
|
3
|
+
import { EnumScoutStateStatus, setHerdModules, setStatus, setHerdModulesLoadingState, setHerdModulesLoadedInMs, setHerdModulesApiDuration, setUserApiDuration, setDataProcessingDuration, setLocalStorageDuration, setUser, setDataSource, setDataSourceInfo, } from "../store/scout";
|
|
4
4
|
import { EnumHerdModulesLoadingState } from "../types/herd_module";
|
|
5
5
|
import { server_load_herd_modules } from "../helpers/herds";
|
|
6
6
|
import { server_get_user } from "../helpers/users";
|
|
@@ -275,32 +275,38 @@ export function useScoutRefresh(options = {}) {
|
|
|
275
275
|
const dataProcessingDuration = Date.now() - dataProcessingStartTime;
|
|
276
276
|
timingRefs.current.dataProcessingDuration = dataProcessingDuration;
|
|
277
277
|
dispatch(setDataProcessingDuration(dataProcessingDuration));
|
|
278
|
-
// Step 5: Handle localStorage operations
|
|
278
|
+
// // Step 5: Handle localStorage operations
|
|
279
279
|
const localStorageStartTime = Date.now();
|
|
280
|
-
try {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
280
|
+
// try {
|
|
281
|
+
// // Check local storage for a last selected herd
|
|
282
|
+
// const lastSelectedHerd = localStorage.getItem("last_selected_herd");
|
|
283
|
+
// if (lastSelectedHerd) {
|
|
284
|
+
// const found_herd = compatible_new_herd_modules.find(
|
|
285
|
+
// (hm) => hm.herd.id.toString() === lastSelectedHerd,
|
|
286
|
+
// )?.herd;
|
|
287
|
+
// // If herd is found then set it
|
|
288
|
+
// if (found_herd) {
|
|
289
|
+
// dispatch(setActiveHerdId(found_herd.id.toString()));
|
|
290
|
+
// }
|
|
291
|
+
// }
|
|
292
|
+
// // If there is no last selected herd then select the first one
|
|
293
|
+
// else if (compatible_new_herd_modules.length > 0) {
|
|
294
|
+
// const firstHerdId = compatible_new_herd_modules[0].herd.id.toString();
|
|
295
|
+
// localStorage.setItem("last_selected_herd", firstHerdId);
|
|
296
|
+
// dispatch(setActiveHerdId(firstHerdId));
|
|
297
|
+
// }
|
|
298
|
+
// } catch (localStorageError) {
|
|
299
|
+
// console.warn(
|
|
300
|
+
// "[useScoutRefresh] localStorage not available:",
|
|
301
|
+
// localStorageError,
|
|
302
|
+
// );
|
|
303
|
+
// // Fallback: select first herd without localStorage
|
|
304
|
+
// if (compatible_new_herd_modules.length > 0) {
|
|
305
|
+
// dispatch(
|
|
306
|
+
// setActiveHerdId(compatible_new_herd_modules[0].herd.id.toString()),
|
|
307
|
+
// );
|
|
308
|
+
// }
|
|
309
|
+
// }
|
|
304
310
|
const localStorageDuration = Date.now() - localStorageStartTime;
|
|
305
311
|
timingRefs.current.localStorageDuration = localStorageDuration;
|
|
306
312
|
dispatch(setLocalStorageDuration(localStorageDuration));
|