@@ -22,12 +22,8 @@ import { StockfishEngineContext } from 'src/contexts/StockfishEngineContext'
2222import {
2323 collectEngineAnalysisData ,
2424 generateAnalysisCacheKey ,
25- applyEngineAnalysisData ,
2625} from 'src/lib/analysisStorage'
27- import {
28- storeEngineAnalysis ,
29- getEngineAnalysis ,
30- } from 'src/api/analysis/analysis'
26+ import { storeEngineAnalysis } from 'src/api/analysis/analysis'
3127
3228export interface GameAnalysisProgress {
3329 currentMoveIndex : number
@@ -146,80 +142,31 @@ export const useAnalysisController = (
146142 const saveAnalysisToBackendRef = useRef ( saveAnalysisToBackend )
147143 saveAnalysisToBackendRef . current = saveAnalysisToBackend
148144
149- const loadStoredAnalysis = useCallback ( async ( ) => {
150- console . log (
151- 'loadStoredAnalysis called for game:' ,
152- game . id ,
153- 'type:' ,
154- game . type ,
155- )
156-
157- if (
158- ! game . id ||
159- game . type === 'custom-pgn' ||
160- game . type === 'custom-fen' ||
161- game . type === 'tournament'
162- ) {
163- console . log ( 'Skipping analysis load - game not eligible' )
164- return
165- }
166-
167- try {
168- console . log ( 'Fetching stored analysis for game:' , game . id )
169- const storedAnalysis = await getEngineAnalysis ( game . id )
170- console . log ( 'Received stored analysis:' , storedAnalysis )
171-
172- if ( storedAnalysis && storedAnalysis . positions . length > 0 ) {
173- applyEngineAnalysisData ( game . tree , storedAnalysis . positions )
174- setAnalysisState ( ( prev ) => prev + 1 ) // Trigger UI updates
175- console . log (
176- 'Loaded stored analysis:' ,
177- storedAnalysis . positions . length ,
178- 'positions' ,
179- )
180- } else {
181- console . log ( 'No stored analysis found for game:' , game . id )
182- }
183- } catch ( error ) {
184- console . warn ( 'Failed to load stored analysis:' , error )
185- // Don't show error to user as this is background functionality
186- }
187- } , [ game . id , game . type ] )
188-
189- // Load stored analysis when game changes
190145 useEffect ( ( ) => {
191- // Reset states for new game
192146 setHasUnsavedAnalysis ( false )
193147 setIsAutoSaving ( false )
194148 setLastSavedCacheKey ( '' )
195- loadStoredAnalysis ( )
196- } , [ loadStoredAnalysis ] )
149+ } , [ game . id , game . type ] )
197150
198- // Mark analysis as unsaved when new analysis comes in
199151 useEffect ( ( ) => {
200152 if ( analysisState > 0 ) {
201153 setHasUnsavedAnalysis ( true )
202154 }
203155 } , [ analysisState ] )
204156
205- // Setup auto-save timer
206157 useEffect ( ( ) => {
207- // Clear existing timer
208158 if ( autoSaveTimerRef . current ) {
209159 clearInterval ( autoSaveTimerRef . current )
210160 }
211161
212- // Set up new timer to save every 10 seconds
213162 autoSaveTimerRef . current = setInterval ( ( ) => {
214163 saveAnalysisToBackendRef . current ( )
215164 } , 10000 )
216165
217- // Cleanup on unmount or game change - save one last time
218166 return ( ) => {
219167 if ( autoSaveTimerRef . current ) {
220168 clearInterval ( autoSaveTimerRef . current )
221169 }
222- // Final save when component unmounts or game changes
223170 saveAnalysisToBackendRef . current ( )
224171 }
225172 } , [ game . id ] )
@@ -505,15 +452,14 @@ export const useAnalysisController = (
505452 resetProgress : resetGameAnalysisProgress ,
506453 isEnginesReady : stockfish . isReady ( ) && maia . status === 'ready' ,
507454 saveAnalysis : saveAnalysisToBackend ,
508- loadStoredAnalysis,
509455 autoSave : {
510456 hasUnsavedChanges : hasUnsavedAnalysis ,
511457 isSaving : isAutoSaving ,
512458 status : isAutoSaving
513- ? 'saving'
459+ ? ( 'saving' as const )
514460 : hasUnsavedAnalysis
515- ? 'unsaved'
516- : 'saved' ,
461+ ? ( 'unsaved' as const )
462+ : ( 'saved' as const ) ,
517463 } ,
518464 } ,
519465 }
0 commit comments