diff --git a/client/components/providers/GeolocationProvider.tsx b/client/components/providers/GeolocationProvider.tsx index 0d32b1e..869f9fb 100644 --- a/client/components/providers/GeolocationProvider.tsx +++ b/client/components/providers/GeolocationProvider.tsx @@ -3,17 +3,21 @@ import React, { ReactNode, useEffect } from 'react' import { Platform } from 'react-native' import { Constants } from '@/constants/Constants' import { useAuth } from '@/hooks/useAuth' +import { useSetLocationAccuracy } from '@/hooks/useGame' import { useGeolocationMutation } from '@/hooks/mutations/useGeolocationMutation' import { useQueuedLocations, useSetLastPlayerLocation, useSetLastPlayerLocations, useUnqueueLocation } from '@/hooks/useLocation' import { isAuthValid } from '@/utils/features/auth/authSlice' import { PlayerLocation } from '@/utils/features/location/locationSlice' import { useStartGeolocationServiceEffect } from '@/utils/geolocation' +import * as SecureStore from '@/utils/SecureStore' import { socket } from '@/utils/socket' +import { Accuracy } from 'expo-location' export default function GeolocationProvider({ children }: { children: ReactNode }) { useStartGeolocationServiceEffect() const auth = useAuth() + const setLocationAccuracy = useSetLocationAccuracy() const geolocationsQueue = useQueuedLocations() const unqueueLocation = useUnqueueLocation() const setLastPlayerLocations = useSetLastPlayerLocations() @@ -23,6 +27,17 @@ export default function GeolocationProvider({ children }: { children: ReactNode onPostSuccess: (data, variables) => unqueueLocation(variables), onError: ({ response, error }) => console.error(response, error), }) + + useEffect(() => { + SecureStore.getItemAsync('locationAccuracy').then(locationAccuracyString => { + if (!locationAccuracyString) + setLocationAccuracy(Accuracy.Balanced) + else if (locationAccuracyString === 'null') + setLocationAccuracy(null) + else + setLocationAccuracy(+locationAccuracyString) + }) + }, []) if (Platform.OS !== "web") { useEffect(() => { diff --git a/client/utils/features/game/gameSlice.ts b/client/utils/features/game/gameSlice.ts index 2fb443b..1ba4b8c 100644 --- a/client/utils/features/game/gameSlice.ts +++ b/client/utils/features/game/gameSlice.ts @@ -1,5 +1,6 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit' import { Accuracy } from 'expo-location' +import * as SecureStore from '@/utils/SecureStore' export interface RunPayload { id: number @@ -89,6 +90,7 @@ export const gameSlice = createSlice({ }, setLocationAccuracy: (state, action: PayloadAction) => { state.settings.locationAccuracy = action.payload + SecureStore.setItem('locationAccuracy', action.payload?.toString() ?? 'null') } }, }) diff --git a/client/utils/features/location/locationSlice.ts b/client/utils/features/location/locationSlice.ts index 0e2a3da..8146f28 100644 --- a/client/utils/features/location/locationSlice.ts +++ b/client/utils/features/location/locationSlice.ts @@ -1,6 +1,7 @@ -import { Constants } from '@/constants/Constants' import { createSlice, PayloadAction } from '@reduxjs/toolkit' import { LocationObject } from 'expo-location' +import { Constants } from '@/constants/Constants' + export type PlayerLocation = { id?: number diff --git a/client/utils/geolocation.ts b/client/utils/geolocation.ts index 8cb198d..a9a240f 100644 --- a/client/utils/geolocation.ts +++ b/client/utils/geolocation.ts @@ -18,6 +18,7 @@ TaskManager.defineTask(LOCATION_TASK, async ({ data, error }: any) => { } const { locations } = data const lastLoc: Location.LocationObject = locations.at(-1) + console.log("AAAAA", lastLoc) store.dispatch(setLastLocation(lastLoc)) const playerId = store.getState().game.playerId if (socket.active && playerId) {