diff --git a/frontend/src/components/Icons.jsx b/frontend/src/components/Icons.jsx index bfcbb40..1f50d51 100644 --- a/frontend/src/components/Icons.jsx +++ b/frontend/src/components/Icons.jsx @@ -216,6 +216,17 @@ export const Icons = { ), + // Actions + trash: ( + + + + + + + + ), + // Brand gravl: ( diff --git a/frontend/src/pages/WorkoutPage.jsx b/frontend/src/pages/WorkoutPage.jsx index f5c1c65..e7f82ad 100644 --- a/frontend/src/pages/WorkoutPage.jsx +++ b/frontend/src/pages/WorkoutPage.jsx @@ -257,44 +257,64 @@ function WorkoutPage({ day, week, logs, onLogSet, onBack, fetchProgression }) { ) } -function ExerciseCard({ exercise, logs, progression, expanded, onToggle, onLogSet }) { - const [setInputs, setSetInputs] = useState({}) +function ExerciseCard({ exercise, logs, progression, expanded, onToggle, onLogSet, onDeleteSet }) { + const [setList, setSetList] = useState([]) + const [showAddModal, setShowAddModal] = useState(false) useEffect(() => { - // Initialize with suggested weight or last logged - const initial = {} + const initial = [] for (let i = 1; i <= exercise.sets; i++) { const existingLog = logs.find(l => l.set_number === i) - initial[i] = { - weight: existingLog?.weight || progression?.suggestedWeight || '', - reps: existingLog?.reps || '', + initial.push({ + weight: existingLog?.weight?.toString() || progression?.suggestedWeight?.toString() || '', + reps: existingLog?.reps?.toString() || '', completed: existingLog?.completed || false - } + }) } - setSetInputs(initial) + setSetList(initial) }, [exercise, logs, progression]) - const handleInputChange = (setNum, field, value) => { - setSetInputs(prev => ({ - ...prev, - [setNum]: { ...prev[setNum], [field]: value } - })) + const handleInputChange = (idx, field, value) => { + setSetList(prev => prev.map((s, i) => i === idx ? { ...s, [field]: value } : s)) } - const handleComplete = (setNum) => { - const input = setInputs[setNum] + const handleComplete = (idx) => { + const input = setList[idx] const newCompleted = !input.completed - setSetInputs(prev => ({ - ...prev, - [setNum]: { ...prev[setNum], completed: newCompleted } - })) - onLogSet(exercise.id, setNum, input.weight, input.reps, newCompleted) + setSetList(prev => prev.map((s, i) => i === idx ? { ...s, completed: newCompleted } : s)) + onLogSet(exercise.id, idx + 1, input.weight, input.reps, newCompleted) } - const completedSets = Object.values(setInputs).filter(s => s.completed).length + const handleAddNormal = () => { + const last = setList[setList.length - 1] || { weight: '', reps: '' } + setSetList(prev => [...prev, { weight: last.weight, reps: last.reps, completed: false }]) + setShowAddModal(false) + } + + const handleAddDropset = () => { + const last = setList[setList.length - 1] || { weight: '0', reps: '10' } + const baseWeight = parseFloat(last.weight) || 0 + const drop1 = Math.round((baseWeight * 0.80) / 2.5) * 2.5 + const drop2 = Math.round((baseWeight * 0.60) / 2.5) * 2.5 + const newSets = [ + { weight: last.weight, reps: '10', completed: false }, + { weight: drop1.toString(), reps: '10', completed: false }, + { weight: drop2.toString(), reps: '10', completed: false }, + ] + setSetList(prev => [...prev, ...newSets]) + setShowAddModal(false) + } + + const handleDeleteSet = (idx) => { + if (setList.length <= 1) return + setSetList(prev => prev.filter((_, i) => i !== idx)) + if (onDeleteSet) onDeleteSet(exercise.id, idx + 1) + } + + const completedSets = setList.filter(s => s.completed).length return ( -
+
0 ? 'all-done' : ''}`}>

{exercise.name}

@@ -302,8 +322,8 @@ function ExerciseCard({ exercise, logs, progression, expanded, onToggle, onLogSe
{exercise.sets}×{exercise.reps_min}-{exercise.reps_max} - - {completedSets}/{exercise.sets} + + {completedSets}/{setList.length}
@@ -320,32 +340,63 @@ function ExerciseCard({ exercise, logs, progression, expanded, onToggle, onLogSe )}
- {Array.from({ length: exercise.sets }, (_, i) => i + 1).map(setNum => { - const input = setInputs[setNum] || { weight: '', reps: '', completed: false } - return ( -
- Set {setNum} -
- handleInputChange(setNum, 'weight', val)} - /> - × - handleInputChange(setNum, 'reps', val)} - /> -
- + {setList.map((input, idx) => ( +
+ Set {idx + 1} +
+ handleInputChange(idx, 'weight', val)} + /> + × + handleInputChange(idx, 'reps', val)} + />
- ) - })} + + +
+ ))}
+ + + + {showAddModal && ( +
setShowAddModal(false)}> +
e.stopPropagation()}> +

Välj settyp

+ + + +
+
+ )}
)}