From 64633981edf3a096d44f54cafd1f88cc553c5639 Mon Sep 17 00:00:00 2001 From: Clawd Date: Sat, 21 Feb 2026 18:44:58 +0100 Subject: [PATCH] feat(02-02): wire deleteLog through App.jsx and WorkoutPage to ExerciseCard - Added deleteLog function in App.jsx: calls DELETE /api/logs and removes entry from local logs state - Passed onDeleteSet={deleteLog} to WorkoutPage in workout view render - Updated WorkoutPage function signature to accept onDeleteSet prop - Passed onDeleteSet through to each ExerciseCard (ExerciseCard already calls it in handleDeleteSet) - Non-logged sets (404 from backend) silently ignored via catch block --- frontend/src/App.jsx | 23 +++++++++++++++++++++++ frontend/src/pages/WorkoutPage.jsx | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index c787795..dc089a6 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -90,6 +90,28 @@ function App() { } } + const deleteLog = async (programExerciseId, setNumber) => { + try { + await fetch(`${API_URL}/logs`, { + method: 'DELETE', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + user_id: userId, + program_exercise_id: programExerciseId, + date: today, + set_number: setNumber + }) + }) + // Remove from local logs state + setLogs(prev => ({ + ...prev, + [programExerciseId]: (prev[programExerciseId] || []).filter(l => l.set_number !== setNumber) + })) + } catch (err) { + console.error('Failed to delete log:', err) + } + } + const startWorkout = async (day) => { await fetchProgram() // Ensure program is loaded setSelectedDay(day) @@ -135,6 +157,7 @@ function App() { week={currentWeek} logs={logs} onLogSet={logSet} + onDeleteSet={deleteLog} onBack={() => setView('dashboard')} fetchProgression={fetchProgression} /> diff --git a/frontend/src/pages/WorkoutPage.jsx b/frontend/src/pages/WorkoutPage.jsx index e7f82ad..15b3e53 100644 --- a/frontend/src/pages/WorkoutPage.jsx +++ b/frontend/src/pages/WorkoutPage.jsx @@ -47,7 +47,7 @@ function getMuscleGroups(exercises) { return Array.from(groups) } -function WorkoutPage({ day, week, logs, onLogSet, onBack, fetchProgression }) { +function WorkoutPage({ day, week, logs, onLogSet, onDeleteSet, onBack, fetchProgression }) { const [progressions, setProgressions] = useState({}) const [expandedExercise, setExpandedExercise] = useState(null) const [warmupDone, setWarmupDone] = useState(false) @@ -239,6 +239,7 @@ function WorkoutPage({ day, week, logs, onLogSet, onBack, fetchProgression }) { expandedExercise === exercise.id ? null : exercise.id )} onLogSet={onLogSet} + onDeleteSet={onDeleteSet} /> ))}