Pénalité lorsqu'on échoue un défi

This commit is contained in:
2024-12-13 00:02:58 +01:00
parent 63ad84eb8c
commit 4cb2677f45
6 changed files with 34 additions and 9 deletions

View File

@ -29,7 +29,7 @@ export default function ChallengeCard({ challenge, onSuccess, onFail, onDelete,
</View>
<View style={{ flexWrap: 'wrap', flexDirection: 'row', justifyContent: 'space-around', padding: 15 }}>
{onFail && <Button key='failBtn' mode='outlined' icon='cancel' onPress={() => onFail()}>
Passer
Échouer
</Button>}
{onSuccess && <Button key='successBtn' mode='contained' icon='check' onPress={() => onSuccess()}>
Terminer

View File

@ -1,10 +1,10 @@
import { useAuth } from '@/hooks/useAuth'
import { useDownloadChallengeActions } from '@/hooks/useChallengeActions'
import { useChallengeActions, useDownloadChallengeActions } from '@/hooks/useChallengeActions'
import { useDownloadChallenges } from '@/hooks/useChallenges'
import { useGame, useUpdateActiveChallengeId, useUpdateGameState, useUpdateMoney } from '@/hooks/useGame'
import { useGame, useUpdateActiveChallengeId, useUpdateGameState, useUpdateMoney, useUpdatePenalty } from '@/hooks/useGame'
import { useDownloadTrains } from '@/hooks/useTrain'
import { isAuthValid } from '@/utils/features/auth/authSlice'
import { ChallengeActionPayload } from '@/utils/features/challengeActions/challengeActionsSlice'
import { ChallengeAction, ChallengeActionPayload } from '@/utils/features/challengeActions/challengeActionsSlice'
import { Challenge } from '@/utils/features/challenges/challengesSlice'
import { useQuery } from '@tanstack/react-query'
import { ReactNode, useEffect } from 'react'
@ -12,7 +12,9 @@ import { ReactNode, useEffect } from 'react'
export default function GameProvider({ children }: { children: ReactNode }) {
const auth = useAuth()
const game = useGame()
const challengeActions = useChallengeActions()
const updateGameState = useUpdateGameState()
const updatePenalty = useUpdatePenalty()
const updateMoney = useUpdateMoney()
const updateActiveChallengeId = useUpdateActiveChallengeId()
const downloadTrains = useDownloadTrains()
@ -77,6 +79,17 @@ export default function GameProvider({ children }: { children: ReactNode }) {
}
}, [challengesQuery.status, challengesQuery.dataUpdatedAt])
useEffect(() => {
const now = new Date().getTime()
const activeChallenge: ChallengeAction | undefined = challengeActions.challengeActions
.find(challengeAction => challengeAction.penaltyStart && challengeAction.penaltyEnd
&& challengeAction.penaltyStart <= now && now <= challengeAction.penaltyEnd)
if (!activeChallenge || !game.currentRunner)
updatePenalty({ penaltyStart: null, penaltyEnd: null })
else if (activeChallenge && (activeChallenge.penaltyStart !== game.penaltyStart || activeChallenge.penaltyEnd))
updatePenalty({ penaltyStart: activeChallenge.penaltyStart, penaltyEnd: activeChallenge.penaltyEnd })
}, [game.currentRunner, challengeActions])
return <>
{children}
</>

View File

@ -41,7 +41,7 @@ export default function PenaltyBanner() {
</Banner>
<ProgressBar
visible={hasPenalty}
animatedValue={1 - remainingTime / (3 * 60)}
animatedValue={1 - remainingTime / (30 * 60)}
color={MD3Colors.error40}
style={{ height: 6 }} />
</View>