diff --git a/client/components/FreeChaseBanner.tsx b/client/components/FreeChaseBanner.tsx index 9cbc5b8..59d7aa0 100644 --- a/client/components/FreeChaseBanner.tsx +++ b/client/components/FreeChaseBanner.tsx @@ -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 ( 0} animatedValue={1 - remainingTime / (45 * 60)} color={'green'} style={{ height: 6 }} /> 0} icon={({ size }) => } style={{ backgroundColor: MD3Colors.secondary40 }}> diff --git a/client/components/GameProvider.tsx b/client/components/GameProvider.tsx index d063a52..392458b 100644 --- a/client/components/GameProvider.tsx +++ b/client/components/GameProvider.tsx @@ -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 <>