@@ -20,10 +20,8 @@ export default function Board() {
2020 const { game, board, updateGame, updateBoard } = usePlayWithComputerStore ( ) ;
2121 const { onOpen } = useGameResultModal ( )
2222
23- /**
24- * This state will be used to hint animation
25- */
26- const [ isHintClicked , setIsHintClicked ] = useState < boolean > ( false )
23+
24+ const [ clickedHint , setClickedHint ] = useState < IMove | null > ( null ) ;
2725 const cellRefs = useRef < ( HTMLDivElement | null ) [ ] > ( [ ] ) ;
2826 const activeMoveOrder = useDeepCompareMemoize < IActiveGamerData > ( getActiveGamerData ( game as IGame ) ) ;
2927 const opponent : EGamer = activeMoveOrder . gamer . color == EGamer . BLACK ? EGamer . WHITE : EGamer . BLACK ;
@@ -41,7 +39,7 @@ export default function Board() {
4139 } , [ hints ] ) ;
4240
4341 const handleHint = useCallback ( async ( move : IMove ) => {
44- if ( isHintClicked ) return ;
42+ if ( clickedHint ) return ;
4543 if ( ! game ?. isGameStarted ) {
4644 return toast . info ( "Game has not started yet!" ) ;
4745 }
@@ -60,7 +58,7 @@ export default function Board() {
6058 gamer : activeMoveOrder . gamer . color ,
6159 } ) ) )
6260 ] ;
63- setIsHintClicked ( true ) ;
61+ setClickedHint ( move ) ;
6462
6563 setTimeout ( ( ) => {
6664 updateBoard ( board . map ( cell => {
@@ -74,7 +72,7 @@ export default function Board() {
7472 } ) ;
7573 } , 500 ) ; // set timeout is for hint animation
7674
77- } , [ game , board , activeMoveOrder , isHintClicked ] ) ;
75+ } , [ game , board , activeMoveOrder , clickedHint ] ) ;
7876
7977 const handleGameFinish = useCallback ( ( ) => {
8078 const winnerGamer : string | null = getWinnerGamer ( game as IGame , board ) ;
@@ -142,9 +140,9 @@ export default function Board() {
142140 }
143141 } , [ isComputerTurn , board , game ?. isGameStarted ] ) ;
144142
145- // set to initial state when component unmount
143+ // set to initial state when active move order change
146144 useEffect ( ( ) => {
147- setIsHintClicked ( false ) ;
145+ setClickedHint ( null ) ;
148146 } , [ activeMoveOrder ] ) ;
149147
150148
@@ -158,12 +156,13 @@ export default function Board() {
158156
159157 return (
160158 < section
161- className = { ` ${ isHintClicked ? 'pointer-events-none' : '' } relative grid grid-cols-8 grid-rows-8 gap-0.5 sm:gap-1 bg-white` } >
159+ className = " relative grid grid-cols-8 grid-rows-8 gap-0.5 sm:gap-1 bg-white" >
162160 { board . map ( ( cell , index ) => < Cell key = { `${ cell . row } ${ cell . col } ` }
163161 onClick = { handleHint }
164162 hasHint = { hints . includes ( index ) }
165163 stone = { cell }
166164 activeGamer = { activeMoveOrder . gamer . color }
165+ clickedHint = { clickedHint }
167166 ref = { ( element : HTMLDivElement ) => {
168167 cellRefs . current [ index ] = element
169168 } } /> ) }
0 commit comments