Stockage du choix de précision de géolocalisation
This commit is contained in:
parent
590539a979
commit
956e9b6ffd
@ -3,17 +3,21 @@ import React, { ReactNode, useEffect } from 'react'
|
|||||||
import { Platform } from 'react-native'
|
import { Platform } from 'react-native'
|
||||||
import { Constants } from '@/constants/Constants'
|
import { Constants } from '@/constants/Constants'
|
||||||
import { useAuth } from '@/hooks/useAuth'
|
import { useAuth } from '@/hooks/useAuth'
|
||||||
|
import { useSetLocationAccuracy } from '@/hooks/useGame'
|
||||||
import { useGeolocationMutation } from '@/hooks/mutations/useGeolocationMutation'
|
import { useGeolocationMutation } from '@/hooks/mutations/useGeolocationMutation'
|
||||||
import { useQueuedLocations, useSetLastPlayerLocation, useSetLastPlayerLocations, useUnqueueLocation } from '@/hooks/useLocation'
|
import { useQueuedLocations, useSetLastPlayerLocation, useSetLastPlayerLocations, useUnqueueLocation } from '@/hooks/useLocation'
|
||||||
import { isAuthValid } from '@/utils/features/auth/authSlice'
|
import { isAuthValid } from '@/utils/features/auth/authSlice'
|
||||||
import { PlayerLocation } from '@/utils/features/location/locationSlice'
|
import { PlayerLocation } from '@/utils/features/location/locationSlice'
|
||||||
import { useStartGeolocationServiceEffect } from '@/utils/geolocation'
|
import { useStartGeolocationServiceEffect } from '@/utils/geolocation'
|
||||||
|
import * as SecureStore from '@/utils/SecureStore'
|
||||||
import { socket } from '@/utils/socket'
|
import { socket } from '@/utils/socket'
|
||||||
|
import { Accuracy } from 'expo-location'
|
||||||
|
|
||||||
export default function GeolocationProvider({ children }: { children: ReactNode }) {
|
export default function GeolocationProvider({ children }: { children: ReactNode }) {
|
||||||
useStartGeolocationServiceEffect()
|
useStartGeolocationServiceEffect()
|
||||||
|
|
||||||
const auth = useAuth()
|
const auth = useAuth()
|
||||||
|
const setLocationAccuracy = useSetLocationAccuracy()
|
||||||
const geolocationsQueue = useQueuedLocations()
|
const geolocationsQueue = useQueuedLocations()
|
||||||
const unqueueLocation = useUnqueueLocation()
|
const unqueueLocation = useUnqueueLocation()
|
||||||
const setLastPlayerLocations = useSetLastPlayerLocations()
|
const setLastPlayerLocations = useSetLastPlayerLocations()
|
||||||
@ -23,6 +27,17 @@ export default function GeolocationProvider({ children }: { children: ReactNode
|
|||||||
onPostSuccess: (data, variables) => unqueueLocation(variables),
|
onPostSuccess: (data, variables) => unqueueLocation(variables),
|
||||||
onError: ({ response, error }) => console.error(response, error),
|
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") {
|
if (Platform.OS !== "web") {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
||||||
import { Accuracy } from 'expo-location'
|
import { Accuracy } from 'expo-location'
|
||||||
|
import * as SecureStore from '@/utils/SecureStore'
|
||||||
|
|
||||||
export interface RunPayload {
|
export interface RunPayload {
|
||||||
id: number
|
id: number
|
||||||
@ -89,6 +90,7 @@ export const gameSlice = createSlice({
|
|||||||
},
|
},
|
||||||
setLocationAccuracy: (state, action: PayloadAction<Accuracy | null>) => {
|
setLocationAccuracy: (state, action: PayloadAction<Accuracy | null>) => {
|
||||||
state.settings.locationAccuracy = action.payload
|
state.settings.locationAccuracy = action.payload
|
||||||
|
SecureStore.setItem('locationAccuracy', action.payload?.toString() ?? 'null')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { Constants } from '@/constants/Constants'
|
|
||||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
import { createSlice, PayloadAction } from '@reduxjs/toolkit'
|
||||||
import { LocationObject } from 'expo-location'
|
import { LocationObject } from 'expo-location'
|
||||||
|
import { Constants } from '@/constants/Constants'
|
||||||
|
|
||||||
|
|
||||||
export type PlayerLocation = {
|
export type PlayerLocation = {
|
||||||
id?: number
|
id?: number
|
||||||
|
@ -18,6 +18,7 @@ TaskManager.defineTask(LOCATION_TASK, async ({ data, error }: any) => {
|
|||||||
}
|
}
|
||||||
const { locations } = data
|
const { locations } = data
|
||||||
const lastLoc: Location.LocationObject = locations.at(-1)
|
const lastLoc: Location.LocationObject = locations.at(-1)
|
||||||
|
console.log("AAAAA", lastLoc)
|
||||||
store.dispatch(setLastLocation(lastLoc))
|
store.dispatch(setLastLocation(lastLoc))
|
||||||
const playerId = store.getState().game.playerId
|
const playerId = store.getState().game.playerId
|
||||||
if (socket.active && playerId) {
|
if (socket.active && playerId) {
|
||||||
|
Loading…
Reference in New Issue
Block a user