+
+
+
+
+
+
+
+
+ onPatch({
+ progression_level: e.target.value === '' ? '' : parseInt(e.target.value, 10),
+ })
+ }
+ />
+
+
+
+
+
+
+ >
+ )
+}
+
function emptyForm() {
return {
title: '',
@@ -237,6 +357,8 @@ function ExerciseFormPage() {
const [variantDraft, setVariantDraft] = useState(() => emptyVariantDraft())
const [variantSavingId, setVariantSavingId] = useState(null)
const [variantBusy, setVariantBusy] = useState(false)
+ const [variantEditSelection, setVariantEditSelection] = useState(null)
+ const variantsDetailsRef = useRef(null)
const [mediaFile, setMediaFile] = useState(null)
const [mediaType, setMediaType] = useState('image')
@@ -284,6 +406,7 @@ function ExerciseFormPage() {
setMediaList([])
setVariants([])
setVariantDraft(emptyVariantDraft())
+ setVariantEditSelection(null)
setLoading(false)
return
}
@@ -297,6 +420,7 @@ function ExerciseFormPage() {
setMediaList(exercise.media || [])
setVariants((exercise.variants || []).map(apiVariantToRow))
setVariantDraft(emptyVariantDraft())
+ setVariantEditSelection(null)
} catch (err) {
if (!cancelled) {
alert(err.message || 'Übung nicht ladbar')
@@ -312,6 +436,19 @@ function ExerciseFormPage() {
}
}, [isEdit, exerciseId, navigate])
+ useEffect(() => {
+ if (variantEditSelection == null || variantEditSelection === 'new') return
+ if (!variants.some((v) => v.id === variantEditSelection)) {
+ setVariantEditSelection(null)
+ }
+ }, [variants, variantEditSelection])
+
+ useEffect(() => {
+ if (variantEditSelection != null && variantsDetailsRef.current) {
+ variantsDetailsRef.current.open = true
+ }
+ }, [variantEditSelection])
+
const updateFormField = (field, value) => {
setFormData((prev) => ({ ...prev, [field]: value }))
}
@@ -493,6 +630,7 @@ function ExerciseFormPage() {
setVariantBusy(true)
try {
await api.deleteExerciseVariant(exerciseId, id)
+ if (variantEditSelection === id) setVariantEditSelection(null)
await refreshVariants()
} catch (e) {
alert(e.message || String(e))
@@ -530,9 +668,11 @@ function ExerciseFormPage() {
}
setVariantBusy(true)
try {
- await api.createExerciseVariant(exerciseId, payload)
+ const created = await api.createExerciseVariant(exerciseId, payload)
setVariantDraft(emptyVariantDraft())
await refreshVariants()
+ if (created?.id != null) setVariantEditSelection(created.id)
+ else setVariantEditSelection(null)
} catch (err) {
alert(err.message || String(err))
} finally {
@@ -542,6 +682,12 @@ function ExerciseFormPage() {
const availableSkills = skillsCatalog.filter((s) => !formData.skills.some((x) => x.skill_id === s.id))
+ const selectedVariantForEdit =
+ typeof variantEditSelection === 'number' ? variants.find((v) => v.id === variantEditSelection) : null
+ const selectedVariantIdx = selectedVariantForEdit
+ ? variants.findIndex((v) => v.id === selectedVariantForEdit.id)
+ : -1
+
if (loading) {
return (
-
Übungsvarianten
-
- Alternative Ausführungen zur Stammübung. Reihenfolge (Nach oben/unten) steuert Darstellung und Auswahl in der
- Trainingsplanung. „Voraussetzung“ verknüpft Varianten für spätere Progressions-Serien als Blöcke.
-
- {variants.length === 0 && (
-
Noch keine Varianten angelegt.
- )}
- {variants.map((v, idx) => (
-
-
- #{idx + 1}
-
-
-
-
-
+
+
+ Übungsvarianten
+
+ {variants.length === 0
+ ? 'keine'
+ : `${variants.length} ${variants.length === 1 ? 'Variante' : 'Varianten'}`}
+
+
+
+
+ Pro Durchgang nur eine Variante bearbeiten – weniger Scrollen. Reihenfolge entspricht Planung und Auswahl im
+ Training; „Voraussetzung“ nutzt ihr später für Progressions-Serien.
+
+
+ {variants.length > 0 && (
-
- updateVariantField(v.id, { variant_name: e.target.value })}
- minLength={3}
- />
-
-
-
-
-
-
- updateVariantField(v.id, { execution_changes: html })}
- placeholder="Was unterscheidet diese Variante?"
- minHeight="100px"
- />
-
-
-
-
-
-
-
-
-
-
-
-
-
- updateVariantField(v.id, {
- progression_level: e.target.value === '' ? '' : parseInt(e.target.value, 10),
- })
- }
- />
-
-
-
-
-
-
-
- ))}
-
-
+ )}
+
+ {variants.length === 0 && (
+
+ Noch keine Varianten – optional für andere Ausführung, Dauer oder Material in Planung und Training.
+
+ )}
+
+ {variants.length === 0 && variantEditSelection !== 'new' && (
+
+ )}
+
+ {variantEditSelection === 'new' && (
+
+ )}
+
+ {selectedVariantForEdit && (
+
+
+
+ Pos. {selectedVariantIdx + 1} von {variants.length}
+
+
+
+
+
+
+
updateVariantField(selectedVariantForEdit.id, patch)}
+ prerequisiteOthers={variants.filter((o) => o.id !== selectedVariantForEdit.id)}
+ rteMinHeight="110px"
+ />
+
+ )}
+
+ {variants.length > 0 && variantEditSelection == null && (
+
+ Wähle eine Variante zum Bearbeiten oder „Neue Variante anlegen…“.
+
+ )}
+
+
)}
{isEdit && (