Skip to content

Commit d0fee62

Browse files
fix: overwrite drills after reset
1 parent b91e34f commit d0fee62

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/hooks/useOpeningDrillController/useOpeningDrillController.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,24 @@ export const useOpeningDrillController = (
300300

301301
const performanceData = evaluateDrillPerformance(drillGame)
302302
setCurrentPerformanceData(performanceData)
303-
setCompletedDrills((prev) => [...prev, performanceData.drill])
303+
304+
// Check if this drill already exists in completedDrills and update it instead of adding new
305+
setCompletedDrills((prev) => {
306+
const existingIndex = prev.findIndex(
307+
(completedDrill) =>
308+
completedDrill.selection.id === drillGame.selection.id,
309+
)
310+
311+
if (existingIndex !== -1) {
312+
// Update existing drill
313+
const updated = [...prev]
314+
updated[existingIndex] = performanceData.drill
315+
return updated
316+
} else {
317+
// Add new drill
318+
return [...prev, performanceData.drill]
319+
}
320+
})
304321

305322
// Don't remove from remaining drills here - do it in moveToNextDrill
306323
// This ensures proper counting for the performance modal

0 commit comments

Comments
 (0)