Boutons de démarrage du jeu fonctionnels

This commit is contained in:
2024-12-11 21:33:51 +01:00
parent c28097d443
commit 61b0cd51ae
9 changed files with 116 additions and 41 deletions

View 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}
</>
}