Téléchargmeent des mises à jour de solde

This commit is contained in:
2024-12-13 23:07:37 +01:00
parent 4a33963c12
commit 02304527d3
7 changed files with 82 additions and 4 deletions

View File

@ -2,6 +2,7 @@ import { useAuth } from '@/hooks/useAuth'
import { useChallengeActions, useDownloadChallengeActions } from '@/hooks/useChallengeActions'
import { useDownloadChallenges } from '@/hooks/useChallenges'
import { useGame, useUpdateActiveChallengeId, useUpdateGameState, useUpdateMoney, useUpdatePenalty } from '@/hooks/useGame'
import { useDownloadMoneyUpdates } from '@/hooks/useMoneyUpdates'
import { useDownloadTrains } from '@/hooks/useTrain'
import { isAuthValid } from '@/utils/features/auth/authSlice'
import { ChallengeAction, ChallengeActionPayload } from '@/utils/features/challengeActions/challengeActionsSlice'
@ -20,6 +21,7 @@ export default function GameProvider({ children }: { children: ReactNode }) {
const downloadTrains = useDownloadTrains()
const downloadChallenges = useDownloadChallenges()
const downloadChallengeActions = useDownloadChallengeActions()
const downloadMoneyUpdates = useDownloadMoneyUpdates()
const gameQuery = useQuery({
queryKey: ['get-game', auth.token],
@ -63,11 +65,11 @@ export default function GameProvider({ children }: { children: ReactNode }) {
}, [trainsQuery.status, trainsQuery.dataUpdatedAt])
const challengesQuery = useQuery({
queryKey: ['get-challenges', game.playerId, auth.token],
queryKey: ['get-challenges', auth.token],
queryFn: () => fetch(`${process.env.EXPO_PUBLIC_TRAINTRAPE_MOI_SERVER}/challenges/?size=10000`, {
headers: { "Authorization": `Bearer ${auth.token}` }}
).then(resp => resp.json()),
enabled: isAuthValid(auth) && !!game.playerId,
enabled: isAuthValid(auth),
refetchInterval: 5000,
})
useEffect(() => {
@ -79,6 +81,19 @@ export default function GameProvider({ children }: { children: ReactNode }) {
}
}, [challengesQuery.status, challengesQuery.dataUpdatedAt])
const moneyUpdatesQuery = useQuery({
queryKey: ['get-money-updates', game.playerId, auth.token],
queryFn: () => fetch(`${process.env.EXPO_PUBLIC_TRAINTRAPE_MOI_SERVER}/money-updates/?playerId=${game.playerId}&size=10000`, {
headers: { "Authorization": `Bearer ${auth.token}` }}
).then(resp => resp.json()),
enabled: isAuthValid(auth) && !!game.playerId,
refetchInterval: 5000,
})
useEffect(() => {
if (moneyUpdatesQuery.isSuccess && moneyUpdatesQuery.data)
downloadMoneyUpdates(moneyUpdatesQuery.data)
}, [moneyUpdatesQuery.status, moneyUpdatesQuery.dataUpdatedAt])
useEffect(() => {
const now = new Date().getTime()
const activeChallenge: ChallengeAction | undefined = challengeActions.challengeActions

View File

@ -5,6 +5,7 @@ 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'
export default function GeolocationProvider({ children }: { children: ReactNode }) {
useStartGeolocationServiceEffect()
@ -36,8 +37,9 @@ export default function GeolocationProvider({ children }: { children: ReactNode
headers: {
"Authorization": `Bearer ${auth.token}`,
"Content-Type": "application/json",
}}
).then(resp => resp.json()),
},
}).then(resp => resp.json()),
enabled: isAuthValid(auth),
refetchInterval: 5000,
})
useEffect(() => {