Pénalité lorsqu'on échoue un défi
This commit is contained in:
@ -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
|
||||
|
@ -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}
|
||||
</>
|
||||
|
@ -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>
|
||||
|
Reference in New Issue
Block a user