@@ -527,6 +527,23 @@ export const useOpeningDrillController = (
527527 currentMove : 'Preparing analysis...' ,
528528 } )
529529
530+ // Submit drill data to backend if session ID is available
531+ if ( configuration . sessionId ) {
532+ try {
533+ await submitOpeningDrill ( {
534+ session_id : configuration . sessionId ,
535+ opening_fen : drillGame . selection . variation
536+ ? drillGame . selection . variation . fen
537+ : drillGame . selection . opening . fen ,
538+ side_played : drillGame . selection . playerColor ,
539+ moves_played_uci : drillGame . moves ,
540+ } )
541+ } catch ( error ) {
542+ console . error ( 'Failed to submit drill to backend:' , error )
543+ // Continue even if backend submission fails
544+ }
545+ }
546+
530547 // Ensure all positions in the drill are analyzed to sufficient depth
531548 if ( ensureAnalysisCompleteRef . current ) {
532549 const drillNodes : GameNode [ ] = [ ]
@@ -565,23 +582,6 @@ export const useOpeningDrillController = (
565582 }
566583 } )
567584
568- // Submit drill data to backend if session ID is available
569- if ( configuration . sessionId ) {
570- try {
571- await submitOpeningDrill ( {
572- session_id : configuration . sessionId ,
573- opening_fen : drillGame . selection . variation
574- ? drillGame . selection . variation . fen
575- : drillGame . selection . opening . fen ,
576- side_played : drillGame . selection . playerColor ,
577- moves_played_uci : drillGame . moves ,
578- } )
579- } catch ( error ) {
580- console . error ( 'Failed to submit drill to backend:' , error )
581- // Continue even if backend submission fails
582- }
583- }
584-
585585 setShowPerformanceModal ( true )
586586 } catch ( error ) {
587587 console . error ( 'Error completing drill analysis:' , error )
@@ -593,7 +593,23 @@ export const useOpeningDrillController = (
593593 [ currentDrillGame , evaluateDrillPerformance , configuration . sessionId ] ,
594594 )
595595
596- const moveToNextDrill = useCallback ( ( ) => {
596+ const moveToNextDrill = useCallback ( async ( ) => {
597+ // Submit drill data to backend if session ID is available
598+ if ( configuration . sessionId && currentDrillGame ) {
599+ try {
600+ await submitOpeningDrill ( {
601+ session_id : configuration . sessionId ,
602+ opening_fen : currentDrillGame . selection . variation
603+ ? currentDrillGame . selection . variation . fen
604+ : currentDrillGame . selection . opening . fen ,
605+ side_played : currentDrillGame . selection . playerColor ,
606+ moves_played_uci : currentDrillGame . moves ,
607+ } )
608+ } catch ( error ) {
609+ console . error ( 'Failed to submit drill to backend:' , error )
610+ }
611+ }
612+
597613 setShowPerformanceModal ( false )
598614 setCurrentPerformanceData ( null )
599615 setContinueAnalyzingMode ( false )
0 commit comments