From 956e9b6ffd5ce2752015aa459ed355a51c3ba13b Mon Sep 17 00:00:00 2001 From: Emmy D'Anello Date: Thu, 19 Dec 2024 17:33:17 +0100 Subject: [PATCH] =?UTF-8?q?Stockage=20du=20choix=20de=20pr=C3=A9cision=20d?= =?UTF-8?q?e=20g=C3=A9olocalisation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/providers/GeolocationProvider.tsx | 15 +++++++++++++++ client/utils/features/game/gameSlice.ts | 2 ++ client/utils/features/location/locationSlice.ts | 3 ++- client/utils/geolocation.ts | 1 + 4 files changed, 20 insertions(+), 1 deletion(-) 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) {