Skip to content

Commit ff41c20

Browse files
fix: only enable auto-saving in analysis page
1 parent 3fe9cc5 commit ff41c20

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/hooks/useAnalysisController/useAnalysisController.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export interface GameAnalysisConfig {
4141
export const useAnalysisController = (
4242
game: AnalyzedGame,
4343
initialOrientation?: 'white' | 'black',
44+
enableAutoSave = true,
4445
) => {
4546
const defaultOrientation = initialOrientation
4647
? initialOrientation
@@ -86,6 +87,7 @@ export const useAnalysisController = (
8687

8788
const saveAnalysisToBackend = useCallback(async () => {
8889
if (
90+
!enableAutoSave ||
8991
!game.id ||
9092
game.type === 'custom-pgn' ||
9193
game.type === 'custom-fen' ||
@@ -137,7 +139,14 @@ export const useAnalysisController = (
137139
} finally {
138140
setIsAutoSaving(false)
139141
}
140-
}, [game.id, game.type, game.tree, lastSavedCacheKey, hasUnsavedAnalysis])
142+
}, [
143+
enableAutoSave,
144+
game.id,
145+
game.type,
146+
game.tree,
147+
lastSavedCacheKey,
148+
hasUnsavedAnalysis,
149+
])
141150

142151
const saveAnalysisToBackendRef = useRef(saveAnalysisToBackend)
143152
saveAnalysisToBackendRef.current = saveAnalysisToBackend
@@ -155,6 +164,10 @@ export const useAnalysisController = (
155164
}, [analysisState])
156165

157166
useEffect(() => {
167+
if (!enableAutoSave) {
168+
return
169+
}
170+
158171
if (autoSaveTimerRef.current) {
159172
clearInterval(autoSaveTimerRef.current)
160173
}
@@ -169,7 +182,7 @@ export const useAnalysisController = (
169182
}
170183
saveAnalysisToBackendRef.current()
171184
}
172-
}, [game.id])
185+
}, [game.id, enableAutoSave])
173186

174187
// Simple batch analysis functions that reuse existing analysis infrastructure
175188
const startGameAnalysis = useCallback(

src/pages/openings/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ const OpeningsPage: NextPage = () => {
284284
type: 'play' as const,
285285
},
286286
controller.currentDrill?.playerColor || 'white',
287+
false, // Disable auto-saving on openings page
287288
)
288289

289290
// Function to ensure all positions have sufficient analysis

src/pages/puzzles.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ const Train: React.FC<Props> = ({
296296
const analysisController = useAnalysisController(
297297
analyzedGame,
298298
controller.orientation,
299+
false, // Disable auto-saving on puzzles page
299300
)
300301

301302
const { width } = useContext(WindowSizeContext)

0 commit comments

Comments
 (0)