Correction vidange de la file de géolocalisations à transmettre

This commit is contained in:
Emmy D'Anello 2024-12-15 20:42:21 +01:00
parent 986649a070
commit 1fbd8ee5c3
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
2 changed files with 7 additions and 7 deletions

View File

@ -1,4 +1,4 @@
import { ReactNode, useEffect } from 'react' import { ReactNode, useEffect, useState } from 'react'
import { useAuth } from '@/hooks/useAuth' import { useAuth } from '@/hooks/useAuth'
import { useQueuedLocations, useSetLastPlayerLocations, useUnqueueLocation } from '@/hooks/useLocation' import { useQueuedLocations, useSetLastPlayerLocations, useUnqueueLocation } from '@/hooks/useLocation'
import { useGeolocationMutation } from '@/hooks/mutations/useGeolocationMutation' import { useGeolocationMutation } from '@/hooks/mutations/useGeolocationMutation'
@ -16,16 +16,16 @@ export default function GeolocationProvider({ children }: { children: ReactNode
const setLastPlayerLocations = useSetLastPlayerLocations() const setLastPlayerLocations = useSetLastPlayerLocations()
const geolocationMutation = useGeolocationMutation({ const geolocationMutation = useGeolocationMutation({
auth, auth,
onPostSuccess: (data) => unqueueLocation(data), onPostSuccess: (data, variables) => unqueueLocation(variables),
onError: ({ response, error }) => { console.error(response, error) } onError: ({ response, error }) => console.error(response, error),
}) })
if (Platform.OS !== "web") { if (Platform.OS !== "web") {
useEffect(() => { useEffect(() => {
if (geolocationsQueue.length === 0 || geolocationMutation.isPending || !isAuthValid(auth)) if (geolocationsQueue.length === 0 || geolocationMutation.isPending || !isAuthValid(auth))
return return
const locToSend = geolocationsQueue[0] const locToSend = geolocationsQueue[0]
geolocationMutation.mutate(locToSend) geolocationMutation.mutate(locToSend)
}, [auth, geolocationMutation.status, geolocationsQueue]) }, [auth, geolocationMutation.status, geolocationsQueue])
} }

View File

@ -44,8 +44,8 @@ export const locationSlice = createSlice({
const sentLoc = action.payload const sentLoc = action.payload
state.queuedLocations = state.queuedLocations state.queuedLocations = state.queuedLocations
.filter(loc => new Date(loc.timestamp).getTime() !== sentLoc.timestamp .filter(loc => new Date(loc.timestamp).getTime() !== sentLoc.timestamp
|| loc.coords.latitude !== sentLoc.coords.latitude && loc.coords.latitude !== sentLoc.coords.latitude
|| loc.coords.longitude !== sentLoc.coords.latitude) && loc.coords.longitude !== sentLoc.coords.longitude)
}, },
setLastPlayerLocations: (state, action: PayloadAction<PlayerLocation[]>) => { setLastPlayerLocations: (state, action: PayloadAction<PlayerLocation[]>) => {
state.lastPlayerLocations = action.payload state.lastPlayerLocations = action.payload