Transmission plus immédiate via websockets
This commit is contained in:
@ -1,11 +1,13 @@
|
||||
import { ReactNode, useEffect, useState } from 'react'
|
||||
import { ReactNode, useEffect } from 'react'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
import { useQueuedLocations, useSetLastPlayerLocations, useUnqueueLocation } from '@/hooks/useLocation'
|
||||
import { useQueuedLocations, useSetLastPlayerLocation, useSetLastPlayerLocations, useUnqueueLocation } from '@/hooks/useLocation'
|
||||
import { useGeolocationMutation } from '@/hooks/mutations/useGeolocationMutation'
|
||||
import { useStartGeolocationServiceEffect } from '@/utils/geolocation'
|
||||
import { Platform } from 'react-native'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { isAuthValid } from '@/utils/features/auth/authSlice'
|
||||
import { socket } from '@/utils/socket'
|
||||
import { PlayerLocation } from '@/utils/features/location/locationSlice'
|
||||
|
||||
export default function GeolocationProvider({ children }: { children: ReactNode }) {
|
||||
useStartGeolocationServiceEffect()
|
||||
@ -14,6 +16,7 @@ export default function GeolocationProvider({ children }: { children: ReactNode
|
||||
const geolocationsQueue = useQueuedLocations()
|
||||
const unqueueLocation = useUnqueueLocation()
|
||||
const setLastPlayerLocations = useSetLastPlayerLocations()
|
||||
const setLastPlayerLocation = useSetLastPlayerLocation()
|
||||
const geolocationMutation = useGeolocationMutation({
|
||||
auth,
|
||||
onPostSuccess: (data, variables) => unqueueLocation(variables),
|
||||
@ -47,6 +50,11 @@ export default function GeolocationProvider({ children }: { children: ReactNode
|
||||
setLastPlayerLocations(lastLocationsQuery.data)
|
||||
}, [lastLocationsQuery.status, lastLocationsQuery.dataUpdatedAt])
|
||||
|
||||
socket.on('last-location', (data: PlayerLocation) => {
|
||||
if (data.playerId)
|
||||
setLastPlayerLocation(data)
|
||||
})
|
||||
|
||||
return <>
|
||||
{children}
|
||||
</>
|
||||
|
Reference in New Issue
Block a user