Boutons de démarrage du jeu fonctionnels
This commit is contained in:
26
client/components/GameProvider.tsx
Normal file
26
client/components/GameProvider.tsx
Normal file
@ -0,0 +1,26 @@
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
import { useUpdateGameState } from '@/hooks/useGame'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { ReactNode, useEffect } from 'react'
|
||||
|
||||
export default function GameProvider({ children }: { children: ReactNode }) {
|
||||
const auth = useAuth()
|
||||
const updateGameState = useUpdateGameState()
|
||||
const gameQuery = useQuery({
|
||||
queryKey: ['update-game'],
|
||||
queryFn: () => fetch(`${process.env.EXPO_PUBLIC_TRAINTRAPE_MOI_SERVER}/game/`, {
|
||||
headers: { "Authorization": `Bearer ${auth.token}` }}
|
||||
).then(resp => resp.json()),
|
||||
enabled: auth.loggedIn,
|
||||
refetchInterval: 5000,
|
||||
})
|
||||
const game = gameQuery.data
|
||||
useEffect(() => {
|
||||
if (game)
|
||||
updateGameState(game)
|
||||
}, [game])
|
||||
|
||||
return <>
|
||||
{children}
|
||||
</>
|
||||
}
|
Reference in New Issue
Block a user