@@ -17,6 +17,7 @@ interface Props {
1717 analysisController : any // Analysis controller passed from parent
1818 hover : ( move ?: string ) => void
1919 setHoverArrow : React . Dispatch < React . SetStateAction < DrawShape | null > >
20+ makeMove : ( move : string ) => void
2021}
2122
2223export const OpeningDrillAnalysis : React . FC < Props > = ( {
@@ -29,6 +30,7 @@ export const OpeningDrillAnalysis: React.FC<Props> = ({
2930 analysisController,
3031 hover : parentHover ,
3132 setHoverArrow : parentSetHoverArrow ,
33+ makeMove : parentMakeMove ,
3234} ) => {
3335 const toastId = useRef < string | null > ( null )
3436
@@ -67,44 +69,9 @@ export const OpeningDrillAnalysis: React.FC<Props> = ({
6769
6870 const makeMove = useCallback (
6971 ( move : string ) => {
70- if ( ! analysisEnabled || ! currentNode || ! gameTree ) return
71-
72- const chess = new Chess ( currentNode . fen )
73- const moveAttempt = chess . move ( {
74- from : move . slice ( 0 , 2 ) ,
75- to : move . slice ( 2 , 4 ) ,
76- promotion : move [ 4 ] ? ( move [ 4 ] as PieceSymbol ) : undefined ,
77- } )
78-
79- if ( moveAttempt ) {
80- const newFen = chess . fen ( )
81- const moveString =
82- moveAttempt . from +
83- moveAttempt . to +
84- ( moveAttempt . promotion ? moveAttempt . promotion : '' )
85- const san = moveAttempt . san
86-
87- // For opening drills, always update the main line instead of creating variations
88- // If the move already exists as the main child, just navigate to it
89- if ( currentNode . mainChild ?. move === moveString ) {
90- analysisController . goToNode ( currentNode . mainChild )
91- } else {
92- // Remove any existing children first to replace the main line from this point forward
93- currentNode . removeAllChildren ( )
94-
95- // Create new main line continuation
96- const newNode = gameTree . addMainMove (
97- currentNode ,
98- newFen ,
99- moveString ,
100- san ,
101- analysisController . currentMaiaModel ,
102- )
103- analysisController . goToNode ( newNode )
104- }
105- }
72+ parentMakeMove ( move )
10673 } ,
107- [ analysisEnabled , currentNode , gameTree , analysisController ] ,
74+ [ parentMakeMove ] ,
10875 )
10976
11077 // No-op handlers for blurred analysis components when disabled
@@ -232,6 +199,7 @@ export const OpeningDrillAnalysis: React.FC<Props> = ({
232199 setHoverArrow = {
233200 analysisEnabled ? parentSetHoverArrow : mockSetHoverArrow
234201 }
202+ makeMove = { analysisEnabled ? makeMove : mockMakeMove }
235203 />
236204 </ div >
237205 < BlunderMeter
@@ -340,6 +308,7 @@ export const OpeningDrillAnalysis: React.FC<Props> = ({
340308 setHoverArrow = {
341309 analysisEnabled ? parentSetHoverArrow : mockSetHoverArrow
342310 }
311+ makeMove = { analysisEnabled ? makeMove : mockMakeMove }
343312 />
344313 </ div >
345314 { ! analysisEnabled && (
0 commit comments