Correction banière temps pour poursuite

This commit is contained in:
Emmy D'Anello 2024-12-19 19:19:07 +01:00
parent ced5259272
commit 7f06ac94e8
Signed by: ynerant
GPG Key ID: 3A75C55819C8CF85

View File

@ -7,13 +7,13 @@ import { Banner, MD3Colors, ProgressBar, Text } from "react-native-paper"
export default function FreeChaseBanner() { export default function FreeChaseBanner() {
const game = useGame() const game = useGame()
const chaseFreeTime = game.chaseFreeTime const chaseFreeTime = game.chaseFreeTime
const chaser = !game.gameStarted && !game.currentRunner && chaseFreeTime !== null const chaser = game.gameStarted && !game.currentRunner && chaseFreeTime !== null
const chaseFreeDate = useMemo(() => new Date(chaseFreeTime || 0), [chaseFreeTime]) const chaseFreeDate = useMemo(() => new Date(chaseFreeTime || 0), [chaseFreeTime])
const chaseFreePretty = chaseFreeDate.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' }) const chaseFreePretty = chaseFreeDate.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit' })
const [remainingTime, setRemainingTime] = useState(0) const [remainingTime, setRemainingTime] = useState(0)
const prettyRemainingTime = useMemo(() => `${Math.floor(remainingTime / 60).toString().padStart(2, '0')}:${Math.floor(remainingTime % 60).toString().padStart(2, '0')}`, [remainingTime]) const prettyRemainingTime = useMemo(() => `${Math.floor(remainingTime / 60).toString().padStart(2, '0')}:${Math.floor(remainingTime % 60).toString().padStart(2, '0')}`, [remainingTime])
const iconName = useMemo(() => { const iconName = useMemo(() => {
switch (Math.abs(remainingTime % 4)) { switch (Math.abs(Math.floor(remainingTime) % 4)) {
case 0: return 'hourglass-empty' case 0: return 'hourglass-empty'
case 1: return 'hourglass-end' case 1: return 'hourglass-end'
case 2: return 'hourglass-half' case 2: return 'hourglass-half'
@ -25,7 +25,7 @@ export default function FreeChaseBanner() {
const now = new Date().getTime() const now = new Date().getTime()
if (!chaser || (chaseFreeTime < now && remainingTime < 0)) if (!chaser || (chaseFreeTime < now && remainingTime < 0))
return return
const interval = setInterval(() => setRemainingTime(Math.floor(chaseFreeTime - now) / 1000), 1000) const interval = setInterval(() => setRemainingTime(Math.floor(chaseFreeTime - new Date().getTime()) / 1000), 1000)
return () => clearInterval(interval) return () => clearInterval(interval)
}, [game.gameStarted, game.currentRunner, chaseFreeDate]) }, [game.gameStarted, game.currentRunner, chaseFreeDate])