fix: history on end game

This commit is contained in:
Andre Henriques 2025-04-03 11:23:15 +01:00
parent 14b53886cd
commit 67a4096442

View File

@ -56,7 +56,7 @@ export function Game() {
New Game New Game
</button> </button>
</GameBoard> </GameBoard>
<GameHistory /> <GameHistory plays={lastGame.game.plays} />
</> </>
} }
@ -187,10 +187,10 @@ function WinnerText({ me, result }: { me: PlayResult, result: PlayResult }) {
</div> </div>
} }
function GameHistory() { function GameHistory({ plays }: { plays?: Play[] }) {
const session = useSession(); const session = useSession();
if (!session.currentGame || session.currentGame.plays.length === 0) { if ((!session.currentGame || session.currentGame.plays.length === 0) && plays === undefined) {
return <></> return <></>
} }
@ -199,7 +199,7 @@ function GameHistory() {
Game History Game History
</h2> </h2>
<div> <div>
{session.currentGame.plays.map((play, i) => <div key={i} className="p-2"> {(plays ?? session.currentGame!.plays).map((play, i) => <div key={i} className="p-2">
User played <span className="text-blue-500">{play.user}</span>, and CPU played <span className="text-red-500">{play.cpu}</span>! Winner:{" "} User played <span className="text-blue-500">{play.user}</span>, and CPU played <span className="text-red-500">{play.cpu}</span>! Winner:{" "}
<span className={ <span className={
play.winner === 'tie' ? 'text-yellow-500' : play.winner === 'tie' ? 'text-yellow-500' :