Correction masquage bandeau pourchasseuse

This commit is contained in:
Emmy D'Anello 2024-12-13 01:00:33 +01:00
parent 30a687018f
commit 9e5cdfb132
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85
2 changed files with 9 additions and 7 deletions

View File

@ -7,7 +7,7 @@ import { Banner, MD3Colors, ProgressBar, Text } from "react-native-paper"
export default function FreeChaseBanner() {
const game = useGame()
const chaseFreeTime = game.chaseFreeTime
const stunChase = game.gameStarted && !game.currentRunner && chaseFreeTime !== null
const chaser = !game.gameStarted && !game.currentRunner && chaseFreeTime !== null
const chaseFreeDate = useMemo(() => new Date(chaseFreeTime || 0), [chaseFreeTime])
const chaseFreePretty = chaseFreeDate.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' })
const [remainingTime, setRemainingTime] = useState(0)
@ -22,21 +22,22 @@ export default function FreeChaseBanner() {
}, [remainingTime])
useEffect(() => {
if (!stunChase)
const now = new Date().getTime()
if (!chaser || (chaseFreeTime < now && remainingTime < 0))
return
const interval = setInterval(() => setRemainingTime(Math.floor((chaseFreeDate.getTime() - new Date().getTime()) / 1000)), 1000)
const interval = setInterval(() => setRemainingTime(Math.floor(chaseFreeTime - now) / 1000), 1000)
return () => clearInterval(interval)
}, [stunChase, chaseFreeDate])
}, [game.gameStarted, game.currentRunner, chaseFreeDate])
return (
<View>
<ProgressBar
visible={stunChase}
visible={chaser && remainingTime > 0}
animatedValue={1 - remainingTime / (45 * 60)}
color={'green'}
style={{ height: 6 }} />
<Banner
visible={stunChase}
visible={chaser && remainingTime > 0}
icon={({ size }) => <FontAwesome6 name={iconName} size={size} color={MD3Colors.secondary90} />}
style={{ backgroundColor: MD3Colors.secondary40 }}>
<View>

View File

@ -86,8 +86,9 @@ export default function GameProvider({ children }: { children: ReactNode }) {
&& challengeAction.penaltyStart <= now && now <= challengeAction.penaltyEnd)
if (!activeChallenge || !game.currentRunner)
updatePenalty({ penaltyStart: null, penaltyEnd: null })
else if (activeChallenge && (activeChallenge.penaltyStart !== game.penaltyStart || activeChallenge.penaltyEnd))
else if (activeChallenge && (activeChallenge.penaltyStart !== game.penaltyStart || activeChallenge.penaltyEnd)) {
updatePenalty({ penaltyStart: activeChallenge.penaltyStart, penaltyEnd: activeChallenge.penaltyEnd })
}
}, [game.currentRunner, challengeActions])
return <>