Correction vidange de la file de géolocalisations à transmettre

This commit is contained in:
2024-12-15 20:42:21 +01:00
parent 986649a070
commit 1fbd8ee5c3
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 { useQueuedLocations, useSetLastPlayerLocations, useUnqueueLocation } from '@/hooks/useLocation'
import { useGeolocationMutation } from '@/hooks/mutations/useGeolocationMutation'
@ -16,16 +16,16 @@ export default function GeolocationProvider({ children }: { children: ReactNode
const setLastPlayerLocations = useSetLastPlayerLocations()
const geolocationMutation = useGeolocationMutation({
auth,
onPostSuccess: (data) => unqueueLocation(data),
onError: ({ response, error }) => { console.error(response, error) }
onPostSuccess: (data, variables) => unqueueLocation(variables),
onError: ({ response, error }) => console.error(response, error),
})
if (Platform.OS !== "web") {
useEffect(() => {
if (geolocationsQueue.length === 0 || geolocationMutation.isPending || !isAuthValid(auth))
return
const locToSend = geolocationsQueue[0]
geolocationMutation.mutate(locToSend)
const locToSend = geolocationsQueue[0]
geolocationMutation.mutate(locToSend)
}, [auth, geolocationMutation.status, geolocationsQueue])
}