11/* eslint-disable jsx-a11y/no-static-element-interactions */
22/* eslint-disable jsx-a11y/click-events-have-key-events */
3+ import { Tooltip } from 'react-tooltip'
34import React , { useContext , useMemo , Fragment , useEffect } from 'react'
4- import { TreeControllerContext , WindowSizeContext } from 'src/contexts'
5+ import { WindowSizeContext } from 'src/contexts'
56import { GameNode , AnalyzedGame , Termination , ClientBaseGame } from 'src/types'
6- import { Tooltip } from 'react-tooltip'
7+ import { TuringGame } from 'src/types/turing'
8+ import { useBaseTreeController } from 'src/hooks/useBaseTreeController'
79
8- interface Props {
10+ interface AnalysisProps {
911 game : ClientBaseGame | AnalyzedGame
1012 highlightIndices ?: number [ ]
1113 termination ?: Termination
14+ type : 'analysis'
15+ }
16+
17+ interface TuringProps {
18+ game : TuringGame
19+ highlightIndices ?: number [ ]
20+ termination ?: Termination
21+ type : 'turing'
22+ }
23+
24+ interface PlayProps {
25+ game : ClientBaseGame
26+ highlightIndices ?: number [ ]
27+ termination ?: Termination
28+ type : 'play'
1229}
1330
31+ type Props = AnalysisProps | TuringProps | PlayProps
32+
1433function BlunderIcon ( ) {
1534 return (
1635 < >
@@ -83,19 +102,21 @@ function UnlikelyGoodMoveIcon() {
83102 )
84103}
85104
86- export const AnalysisMovesContainer : React . FC < Props > = ( {
87- game,
88- highlightIndices,
89- termination,
90- } : Props ) => {
91- const { currentNode, goToNode } = useContext ( TreeControllerContext )
92-
105+ export const MovesContainer : React . FC < Props > = ( props ) => {
106+ const { game, highlightIndices, termination, type } = props
93107 const { isMobile } = useContext ( WindowSizeContext )
94108
109+ const controller = useBaseTreeController ( type )
110+ const { currentNode, goToNode, gameTree } = controller
111+
95112 const mainLineNodes = useMemo ( ( ) => {
96- if ( ! game . tree ) return [ ]
97- return game . tree . getMainLine ( )
98- } , [ game . tree ] )
113+ if ( type === 'analysis' ) {
114+ if ( ! game . tree ) return [ ]
115+ return game . tree . getMainLine ( )
116+ } else {
117+ return gameTree . getMainLine ( )
118+ }
119+ } , [ game , type , gameTree ] )
99120
100121 useEffect ( ( ) => {
101122 const handleKeyDown = ( event : KeyboardEvent ) => {
@@ -194,6 +215,8 @@ export const AnalysisMovesContainer: React.FC<Props> = ({
194215 return pairs
195216 } , [ mainLineNodes , isMobile ] )
196217
218+ const showAnnotations = type === 'analysis'
219+
197220 if ( isMobile ) {
198221 return (
199222 < div className = "w-full overflow-x-auto px-2" >
@@ -213,8 +236,10 @@ export const AnalysisMovesContainer: React.FC<Props> = ({
213236 } ${ highlightSet . has ( pairIndex * 2 + 1 ) ? 'bg-human-3/80' : '' } `}
214237 >
215238 < span > { pair . whiteMove . san ?? pair . whiteMove . move } </ span >
216- { pair . whiteMove . blunder && < BlunderIcon /> }
217- { pair . whiteMove . unlikelyGoodMove && < UnlikelyGoodMoveIcon /> }
239+ { showAnnotations && pair . whiteMove . blunder && < BlunderIcon /> }
240+ { showAnnotations && pair . whiteMove . unlikelyGoodMove && (
241+ < UnlikelyGoodMoveIcon />
242+ ) }
218243 </ div >
219244 ) }
220245 { pair . blackMove && (
@@ -227,8 +252,10 @@ export const AnalysisMovesContainer: React.FC<Props> = ({
227252 } ${ highlightSet . has ( pairIndex * 2 + 2 ) ? 'bg-human-3/80' : '' } `}
228253 >
229254 < span > { pair . blackMove . san ?? pair . blackMove . move } </ span >
230- { pair . blackMove . blunder && < BlunderIcon /> }
231- { pair . blackMove . unlikelyGoodMove && < UnlikelyGoodMoveIcon /> }
255+ { showAnnotations && pair . blackMove . blunder && < BlunderIcon /> }
256+ { showAnnotations && pair . blackMove . unlikelyGoodMove && (
257+ < UnlikelyGoodMoveIcon />
258+ ) }
232259 </ div >
233260 ) }
234261 </ React . Fragment >
@@ -266,10 +293,12 @@ export const AnalysisMovesContainer: React.FC<Props> = ({
266293 className = { `col-span-2 flex h-7 flex-1 cursor-pointer flex-row items-center justify-between px-2 text-sm hover:bg-background-2 ${ currentNode === whiteNode && 'bg-human-4/20' } ${ highlightSet . has ( index * 2 + 1 ) && 'bg-human-3/80' } ` }
267294 >
268295 { whiteNode ?. san ?? whiteNode ?. move }
269- { whiteNode ?. blunder && < BlunderIcon /> }
270- { whiteNode ?. unlikelyGoodMove && < UnlikelyGoodMoveIcon /> }
296+ { showAnnotations && whiteNode ?. blunder && < BlunderIcon /> }
297+ { showAnnotations && whiteNode ?. unlikelyGoodMove && (
298+ < UnlikelyGoodMoveIcon />
299+ ) }
271300 </ div >
272- { whiteNode ?. getVariations ( ) . length ? (
301+ { showAnnotations && whiteNode ?. getVariations ( ) . length ? (
273302 < FirstVariation
274303 color = "white"
275304 node = { whiteNode }
@@ -285,10 +314,12 @@ export const AnalysisMovesContainer: React.FC<Props> = ({
285314 className = { `col-span-2 flex h-7 flex-1 cursor-pointer flex-row items-center justify-between px-2 text-sm hover:bg-background-2 ${ currentNode === blackNode && 'bg-human-4/20' } ${ highlightSet . has ( index * 2 + 2 ) && 'bg-human-3/80' } ` }
286315 >
287316 { blackNode ?. san ?? blackNode ?. move }
288- { blackNode ?. blunder && < BlunderIcon /> }
289- { blackNode ?. unlikelyGoodMove && < UnlikelyGoodMoveIcon /> }
317+ { showAnnotations && blackNode ?. blunder && < BlunderIcon /> }
318+ { showAnnotations && blackNode ?. unlikelyGoodMove && (
319+ < UnlikelyGoodMoveIcon />
320+ ) }
290321 </ div >
291- { blackNode ?. getVariations ( ) . length ? (
322+ { showAnnotations && blackNode ?. getVariations ( ) . length ? (
292323 < FirstVariation
293324 color = "black"
294325 node = { blackNode }
0 commit comments