@adventurelabs/scout-core 1.0.92 → 1.0.94

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,3 +1,4 @@
1
+ "use server";
1
2
  import { newServerClient } from "../supabase/server";
2
3
  import { EnumWebResponse, IWebResponse, } from "../types/requests";
3
4
  // Get connectivity by session id using RPC function with coordinates
@@ -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, useState } from "react";
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);
@@ -55,10 +54,10 @@ export function useScoutRealtimeConnectivity(scoutSupabase) {
55
54
  break;
56
55
  }
57
56
  dispatch(setActiveHerdGpsTrackersConnectivity(updatedConnectivity));
58
- }, [connectivity, dispatch]);
57
+ }, [connectivity]);
59
58
  // Fetch initial connectivity data
60
59
  const fetchInitialData = useCallback(async () => {
61
- if (!activeHerdId || hasInitialized === activeHerdId)
60
+ if (!activeHerdId)
62
61
  return;
63
62
  const herdId = activeHerdId; // Type narrowing
64
63
  const activeHerdModule = herdModules.find((hm) => hm.herd.id.toString() === herdId);
@@ -67,7 +66,6 @@ export function useScoutRealtimeConnectivity(scoutSupabase) {
67
66
  const gpsDevices = activeHerdModule.devices.filter((device) => device.device_type &&
68
67
  ["gps_tracker", "gps_tracker_vehicle", "gps_tracker_person"].includes(device.device_type));
69
68
  if (gpsDevices.length === 0) {
70
- setHasInitialized(herdId);
71
69
  return;
72
70
  }
73
71
  console.log(`[Connectivity] Loading data for ${gpsDevices.length} GPS trackers`);
@@ -96,17 +94,14 @@ export function useScoutRealtimeConnectivity(scoutSupabase) {
96
94
  }
97
95
  }));
98
96
  dispatch(setActiveHerdGpsTrackersConnectivity(connectivityData));
99
- setHasInitialized(herdId);
100
97
  console.log(`[Connectivity] Loaded data for ${Object.keys(connectivityData).length} devices`);
101
- }, [activeHerdId, herdModules, hasInitialized, dispatch]);
98
+ }, [activeHerdId]);
102
99
  useEffect(() => {
103
100
  if (!scoutSupabase || !activeHerdId)
104
101
  return;
105
102
  // Clean up existing channels
106
103
  channels.current.forEach((channel) => scoutSupabase.removeChannel(channel));
107
104
  channels.current = [];
108
- // Reset initialization when herd changes
109
- setHasInitialized(null);
110
105
  // Create connectivity channel
111
106
  const channel = scoutSupabase
112
107
  .channel(`${activeHerdId}-connectivity`, { config: { private: true } })
@@ -126,10 +121,5 @@ export function useScoutRealtimeConnectivity(scoutSupabase) {
126
121
  channels.current.forEach((ch) => scoutSupabase.removeChannel(ch));
127
122
  channels.current = [];
128
123
  };
129
- }, [
130
- scoutSupabase,
131
- activeHerdId,
132
- handleConnectivityBroadcast,
133
- fetchInitialData,
134
- ]);
124
+ }, [activeHerdId]);
135
125
  }
@@ -45,8 +45,6 @@ export function useScoutRealtimeDevices(scoutSupabase) {
45
45
  });
46
46
  };
47
47
  useEffect(() => {
48
- if (!scoutSupabase)
49
- return;
50
48
  cleanupChannels();
51
49
  // Create devices channel for active herd
52
50
  if (activeHerdId) {
@@ -54,5 +52,5 @@ export function useScoutRealtimeDevices(scoutSupabase) {
54
52
  channels.current.push(channel);
55
53
  }
56
54
  return cleanupChannels;
57
- }, [scoutSupabase, activeHerdId, handleDeviceBroadcast]);
55
+ }, [activeHerdId]);
58
56
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adventurelabs/scout-core",
3
- "version": "1.0.92",
3
+ "version": "1.0.94",
4
4
  "description": "Core utilities and helpers for Adventure Labs Scout applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",