From ecc2d92edba684ee0e98fb45e64cd4bd989052c9 Mon Sep 17 00:00:00 2001 From: Michael Ficocelli Date: Sun, 27 Oct 2024 20:25:04 -0400 Subject: [PATCH] IPVGO: uncheck the 'show prior move' feature when a new game is started (#1728) --- src/Go/ui/GoGameboardWrapper.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Go/ui/GoGameboardWrapper.tsx b/src/Go/ui/GoGameboardWrapper.tsx index 9157462dc..ecbdfe480 100644 --- a/src/Go/ui/GoGameboardWrapper.tsx +++ b/src/Go/ui/GoGameboardWrapper.tsx @@ -54,6 +54,13 @@ export function GoGameboardWrapper({ showInstructions }: GoGameboardWrapperProps const waitingOnAI = boardState.previousPlayer === GoColor.black && boardState.ai !== GoOpponent.none; const score = getScore(boardState); + // Disable showing prior move if there are no prior moves (if a new game is started while looking at a prior move) + useEffect(() => { + if (boardState.previousBoards.length === 0) { + setShowPriorMove(false); + } + }, [boardState.previousBoards.length]); + // Do not implement useCallback for this function without ensuring GoGameboard still rerenders for every move // Currently this function changing is what triggers a GoGameboard rerender, which is needed async function clickHandler(x: number, y: number) { @@ -139,6 +146,7 @@ export function GoGameboardWrapper({ showInstructions }: GoGameboardWrapperProps function resetState(newBoardSize = boardSize, newOpponent = Go.currentGame.ai) { setScoreOpen(false); setSearchOpen(false); + setShowPriorMove(false); if (boardState.previousPlayer !== null && boardState.previousBoards.length) { resetWinstreak(boardState.ai, false); } @@ -159,9 +167,8 @@ export function GoGameboardWrapper({ showInstructions }: GoGameboardWrapperProps } function showPreviousMove(newValue: boolean) { - if (boardState.previousBoards.length) { - setShowPriorMove(newValue); - } + // Only show prior move if there is previous moves to show + setShowPriorMove(!!boardState.previousBoards.length && newValue); } function setTraditional(newValue: boolean) {