瀏覽代碼

location update

Viktoriia 1 月之前
父節點
當前提交
d43b09c5f1
共有 2 個文件被更改,包括 18 次插入0 次删除
  1. 1 0
      src/modules/api/location/location-api.ts
  2. 17 0
      src/screens/InAppScreens/MapScreen/index.tsx

+ 1 - 0
src/modules/api/location/location-api.ts

@@ -6,6 +6,7 @@ import { FeatureCollection } from '@turf/turf';
 export interface PostGetSettingsReturn extends ResponseType {
   sharing: 0 | 1;
   sharing_regions: 0 | 1;
+  sharing_refresh_interval: number;
 }
 
 export interface PostGetUsersLocationReturn extends ResponseType {

+ 17 - 0
src/screens/InAppScreens/MapScreen/index.tsx

@@ -420,6 +420,7 @@ const MapScreen: any = ({ navigation, route }: { navigation: any; route: any })
   const hideTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
 
   const [markerCoords, setMarkerCoords] = useState<any>(null);
+  const [interval, setInterval] = useState(0);
 
   const isSmallScreen = Dimensions.get('window').width < 383;
   const processedImages = useRef(new Set<string>());
@@ -701,11 +702,27 @@ const MapScreen: any = ({ navigation, route }: { navigation: any; route: any })
     }, [])
   );
 
+  useEffect(() => {
+    if (interval > 0 && showNomads) {
+      const intervalId = setInterval(() => {
+        if (location && token && showNomads) {
+          refetchUsersLocation();
+        }
+      }, interval);
+
+      return () => clearInterval(intervalId);
+    }
+  }, [interval, showNomads]);
+
   useEffect(() => {
     (async () => {
       let { status } = await Location.getForegroundPermissionsAsync();
       const isServicesEnabled = await Location.hasServicesEnabledAsync();
 
+      if (locationSettings && locationSettings.sharing_refresh_interval) {
+        setInterval(locationSettings.sharing_refresh_interval * 1000);
+      }
+
       if (
         status !== 'granted' ||
         !token ||