From 13cab313823e9ca7cd0fc8adb4ded7a68a856a87 Mon Sep 17 00:00:00 2001 From: Zed Date: Sat, 1 Aug 2026 11:29:05 +0200 Subject: [PATCH] =?UTF-8?q?Animation=20de=20victoire=20uniquement=20=C3=A0?= =?UTF-8?q?=20la=20fin=20de=20la=20partie?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit L'overlay de célébration (confettis + avatar du vainqueur) se rejouait à chaque consultation d'une partie terminée. Il n'est désormais déclenché que lorsqu'on arrive depuis la fin de partie (état de navigation justFinished), état consommé ensuite pour qu'un rechargement ne le rejoue pas. Depuis l'historique ou l'accueil, l'écran de fin s'affiche sans célébration. Co-Authored-By: Claude Opus 4.8 --- src/pages/GameOver.tsx | 19 +++++++++++++++++-- src/pages/PlayGame.tsx | 4 +++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/pages/GameOver.tsx b/src/pages/GameOver.tsx index 66993dd..34777ad 100644 --- a/src/pages/GameOver.tsx +++ b/src/pages/GameOver.tsx @@ -1,5 +1,5 @@ import { useEffect, useState } from "react"; -import { useParams, useNavigate } from "react-router-dom"; +import { useParams, useNavigate, useLocation } from "react-router-dom"; import { Trophy, Home, Share2, RotateCcw, Clock, MapPin } from "lucide-react"; import * as Icons from "lucide-react"; import { useLiveQuery } from "dexie-react-hooks"; @@ -20,7 +20,13 @@ export default function GameOver() { const { sessionId } = useParams<{ sessionId: string }>(); const navigate = useNavigate(); const [session, setSession] = useState(null); - const [showCelebration, setShowCelebration] = useState(true); + // Only celebrate when arriving straight from the end of the game, never when + // browsing a finished game from the history. + const routerLocation = useLocation(); + const justFinished = Boolean( + (routerLocation.state as { justFinished?: boolean } | null)?.justFinished, + ); + const [showCelebration, setShowCelebration] = useState(justFinished); const startNewGame = useGameStore((state) => state.startNewGame); const gameConfig = useGameConfig(session?.gameId); @@ -47,6 +53,15 @@ export default function GameOver() { return () => clearTimeout(timer); }, [sessionId]); + // Consume the flag so reloading or coming back to this screen doesn't replay + // the celebration (history.state survives a page reload). + useEffect(() => { + if (justFinished) { + navigate(routerLocation.pathname, { replace: true, state: null }); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); + if (!session) return
Chargement...
; diff --git a/src/pages/PlayGame.tsx b/src/pages/PlayGame.tsx index 760aa87..ddbd9db 100644 --- a/src/pages/PlayGame.tsx +++ b/src/pages/PlayGame.tsx @@ -211,7 +211,9 @@ export default function PlayGame() { } await finishGame(winnerIds); - navigate(`/gameover/${activeSession.id}`); + // `justFinished` déclenche l'animation de victoire (une seule fois) : + // en venant de l'historique, l'écran de fin s'affiche sans célébration. + navigate(`/gameover/${activeSession.id}`, { state: { justFinished: true } }); }; const handleCancelGame = async () => {