feat: enhance exercise selection and training unit management
- Updated ExercisePeekModal to support exercise variants, improving user experience when selecting exercises. - Enhanced ExercisePickerModal with multi-select functionality, allowing users to select multiple exercises at once. - Introduced drag-and-drop support for reordering training unit sections in TrainingUnitSectionsEditor, enhancing organization and usability. - Improved TrainingFrameworkProgramEditPage and TrainingPlanningPage to manage exercise selection and section movement across slots more effectively. - Added new CSS styles in app.css for better visual feedback during drag-and-drop actions and improved layout consistency.
This commit is contained in:
1 parent
354216cb4f
commit
2bfe67879f
6 files changed
+958
-411
No files matched your search
@@ -6,6 +6,7 @@ import ExercisePeekModal from '../components/ExercisePeekModal'
|
||||
import TrainingUnitSectionsEditor from '../components/TrainingUnitSectionsEditor'
|
||||
import {
|
||||
defaultSection,
|
||||
exerciseRow,
|
||||
normalizeUnitToForm,
|
||||
enrichSectionsWithVariants,
|
||||
buildSectionsPayload,
|
||||
@@ -51,7 +52,27 @@ async function enrichFrameworkSlotSections(slots) {
|
||||
return out
|
||||
}
|
||||
|
||||
/** Native-Tooltip für Ziel-Chips (Hover); kurz halten für OS-Tooltip-Limits */
|
||||
async function hydrateExerciseForSlotRow(exercise) {
|
||||
let variants = Array.isArray(exercise?.variants) ? exercise.variants : []
|
||||
let title = exercise?.title || ''
|
||||
const id = exercise?.id
|
||||
if (!id) return null
|
||||
if (!variants.length) {
|
||||
try {
|
||||
const full = await api.getExercise(id)
|
||||
variants = Array.isArray(full?.variants) ? full.variants : []
|
||||
title = full?.title || title
|
||||
} catch {
|
||||
variants = []
|
||||
}
|
||||
}
|
||||
const row = exerciseRow()
|
||||
row.exercise_id = id
|
||||
row.exercise_variant_id = ''
|
||||
row.exercise_title = title
|
||||
row.variants = variants
|
||||
return row
|
||||
}
|
||||
function goalHoverText(g) {
|
||||
const t = (g.title || '').trim() || 'Ohne Titel'
|
||||
const n = (g.notes || '').trim()
|
||||
@@ -182,7 +203,7 @@ export default function TrainingFrameworkProgramEditPage() {
|
||||
const [trainingTypesCatalog, setTrainingTypesCatalog] = useState([])
|
||||
const [targetGroupsCatalog, setTargetGroupsCatalog] = useState([])
|
||||
const [sectionPickerCtx, setSectionPickerCtx] = useState(null)
|
||||
const [peekId, setPeekId] = useState(null)
|
||||
const [peekCtx, setPeekCtx] = useState(null)
|
||||
const [editingGoalIdx, setEditingGoalIdx] = useState(null)
|
||||
const [goalMenuGi, setGoalMenuGi] = useState(null)
|
||||
/** Nur schmal: Stammdaten | Plan (Ziele übereinander, darunter Slots) — Desktop: alles sichtbar */
|
||||
@@ -470,6 +491,52 @@ export default function TrainingFrameworkProgramEditPage() {
|
||||
})
|
||||
}
|
||||
|
||||
const moveSectionsAcrossFrameworkSlots = useCallback(
|
||||
({ fromSlot, fromSectionIdx, toSlot, toSectionIdx }) => {
|
||||
setForm((prev) => {
|
||||
const slots = prev.slots.map((sl) => ({
|
||||
...sl,
|
||||
sections: [...((sl.sections && sl.sections.length) ? sl.sections : [defaultSection('Ablauf')])],
|
||||
}))
|
||||
if (
|
||||
typeof fromSlot !== 'number' ||
|
||||
typeof toSlot !== 'number' ||
|
||||
fromSlot < 0 ||
|
||||
toSlot < 0 ||
|
||||
fromSlot >= slots.length ||
|
||||
toSlot >= slots.length
|
||||
) {
|
||||
return prev
|
||||
}
|
||||
|
||||
const fromSecs = slots[fromSlot].sections
|
||||
if (
|
||||
typeof fromSectionIdx !== 'number' ||
|
||||
fromSectionIdx < 0 ||
|
||||
fromSectionIdx >= fromSecs.length
|
||||
) {
|
||||
return prev
|
||||
}
|
||||
|
||||
const [block] = fromSecs.splice(fromSectionIdx, 1)
|
||||
|
||||
if (fromSlot === toSlot) {
|
||||
let insertAt = toSectionIdx
|
||||
if (fromSectionIdx < toSectionIdx) insertAt = toSectionIdx - 1
|
||||
insertAt = Math.max(0, Math.min(insertAt, fromSecs.length))
|
||||
fromSecs.splice(insertAt, 0, block)
|
||||
return { ...prev, slots }
|
||||
}
|
||||
|
||||
const toSecs = slots[toSlot].sections
|
||||
const ia = Math.max(0, Math.min(toSectionIdx, toSecs.length))
|
||||
toSecs.splice(ia, 0, block)
|
||||
return { ...prev, slots }
|
||||
})
|
||||
},
|
||||
[]
|
||||
)
|
||||
|
||||
const slotChipButtons = (opts) =>
|
||||
form.slots.map((slot, si) => {
|
||||
const isActive = si === mobileSlotIdx
|
||||
@@ -564,6 +631,8 @@ export default function TrainingFrameworkProgramEditPage() {
|
||||
sections={slot.sections}
|
||||
showExecutionExtras={false}
|
||||
wideExerciseGrid
|
||||
slotIndex={si}
|
||||
onMoveSectionsAcrossSlots={moveSectionsAcrossFrameworkSlots}
|
||||
onSectionsChange={(updater) => {
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
@@ -579,14 +648,17 @@ export default function TrainingFrameworkProgramEditPage() {
|
||||
),
|
||||
}))
|
||||
}}
|
||||
onRequestExercisePick={({ sectionIndex, itemIndex }) =>
|
||||
onRequestExercisePick={({ sectionIndex, itemIndex, multi }) =>
|
||||
setSectionPickerCtx({
|
||||
slotIdx: si,
|
||||
sectionIndex,
|
||||
itemIndex,
|
||||
itemIndex: typeof itemIndex === 'number' ? itemIndex : undefined,
|
||||
multi: !!multi,
|
||||
})
|
||||
}
|
||||
onPeekExercise={(id) => setPeekId(id)}
|
||||
onPeekExercise={(id, variantId) =>
|
||||
setPeekCtx({ exerciseId: id, variantId: variantId ?? null })
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1057,21 +1129,45 @@ export default function TrainingFrameworkProgramEditPage() {
|
||||
|
||||
<ExercisePickerModal
|
||||
open={sectionPickerCtx != null}
|
||||
multiSelect={!!sectionPickerCtx?.multi}
|
||||
onClose={() => setSectionPickerCtx(null)}
|
||||
onSelectExercises={
|
||||
sectionPickerCtx?.multi
|
||||
? async (picked) => {
|
||||
if (!sectionPickerCtx || !picked?.length) return
|
||||
const { slotIdx, sectionIndex: sIdx } = sectionPickerCtx
|
||||
const rows = []
|
||||
for (const ex of picked) {
|
||||
const row = await hydrateExerciseForSlotRow(ex)
|
||||
if (row) rows.push(row)
|
||||
}
|
||||
if (!rows.length) return
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
slots: prev.slots.map((sl, ii) =>
|
||||
ii !== slotIdx
|
||||
? sl
|
||||
: {
|
||||
...sl,
|
||||
sections: (
|
||||
sl.sections && sl.sections.length ? sl.sections : [defaultSection('Ablauf')]
|
||||
).map((sec, si) =>
|
||||
si !== sIdx ? sec : { ...sec, items: [...(sec.items || []), ...rows] }
|
||||
),
|
||||
}
|
||||
),
|
||||
}))
|
||||
setSectionPickerCtx(null)
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
onSelectExercise={async (exercise) => {
|
||||
if (!sectionPickerCtx) return
|
||||
if (sectionPickerCtx.multi) return
|
||||
if (typeof sectionPickerCtx.itemIndex !== 'number') return
|
||||
const { slotIdx, sectionIndex: sIdx, itemIndex: iIdx } = sectionPickerCtx
|
||||
let variants = Array.isArray(exercise.variants) ? exercise.variants : []
|
||||
let title = exercise.title || ''
|
||||
if (!variants.length) {
|
||||
try {
|
||||
const full = await api.getExercise(exercise.id)
|
||||
variants = Array.isArray(full.variants) ? full.variants : []
|
||||
title = full.title || title
|
||||
} catch {
|
||||
variants = []
|
||||
}
|
||||
}
|
||||
const row = await hydrateExerciseForSlotRow(exercise)
|
||||
if (!row) return
|
||||
setForm((prev) => ({
|
||||
...prev,
|
||||
slots: prev.slots.map((sl, ii) =>
|
||||
@@ -1085,17 +1181,17 @@ export default function TrainingFrameworkProgramEditPage() {
|
||||
? sec
|
||||
: {
|
||||
...sec,
|
||||
items: (sec.items || []).map((row, ji) =>
|
||||
items: (sec.items || []).map((r2, ji) =>
|
||||
ji !== iIdx
|
||||
? row
|
||||
: row.item_type !== 'exercise'
|
||||
? row
|
||||
? r2
|
||||
: r2.item_type !== 'exercise'
|
||||
? r2
|
||||
: {
|
||||
...row,
|
||||
exercise_id: exercise.id,
|
||||
exercise_variant_id: '',
|
||||
exercise_title: title,
|
||||
variants,
|
||||
...r2,
|
||||
exercise_id: row.exercise_id,
|
||||
exercise_variant_id: row.exercise_variant_id,
|
||||
exercise_title: row.exercise_title,
|
||||
variants: row.variants,
|
||||
}
|
||||
),
|
||||
}
|
||||
@@ -1107,7 +1203,12 @@ export default function TrainingFrameworkProgramEditPage() {
|
||||
}}
|
||||
/>
|
||||
|
||||
<ExercisePeekModal open={peekId != null} exerciseId={peekId || 0} onClose={() => setPeekId(null)} />
|
||||
<ExercisePeekModal
|
||||
open={peekCtx != null}
|
||||
exerciseId={peekCtx?.exerciseId || 0}
|
||||
variantId={peekCtx?.variantId ?? undefined}
|
||||
onClose={() => setPeekCtx(null)}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -7,11 +7,34 @@ import ExercisePeekModal from '../components/ExercisePeekModal'
|
||||
import TrainingUnitSectionsEditor from '../components/TrainingUnitSectionsEditor'
|
||||
import {
|
||||
defaultSection,
|
||||
exerciseRow,
|
||||
normalizeUnitToForm,
|
||||
enrichSectionsWithVariants,
|
||||
buildSectionsPayload,
|
||||
} from '../utils/trainingUnitSectionsForm'
|
||||
|
||||
async function hydrateExerciseForPickerRow(exercise) {
|
||||
let variants = Array.isArray(exercise?.variants) ? exercise.variants : []
|
||||
let title = exercise?.title || ''
|
||||
const id = exercise?.id
|
||||
if (!id) return null
|
||||
if (!variants.length) {
|
||||
try {
|
||||
const full = await api.getExercise(id)
|
||||
variants = Array.isArray(full?.variants) ? full.variants : []
|
||||
title = full?.title || title
|
||||
} catch {
|
||||
variants = []
|
||||
}
|
||||
}
|
||||
const row = exerciseRow()
|
||||
row.exercise_id = id
|
||||
row.exercise_variant_id = ''
|
||||
row.exercise_title = title
|
||||
row.variants = variants
|
||||
return row
|
||||
}
|
||||
|
||||
function TrainingPlanningPage() {
|
||||
const { user } = useAuth()
|
||||
const [groups, setGroups] = useState([])
|
||||
@@ -25,7 +48,7 @@ function TrainingPlanningPage() {
|
||||
const [quickTemplateId, setQuickTemplateId] = useState('')
|
||||
const [exercisePickerOpen, setExercisePickerOpen] = useState(false)
|
||||
const [exercisePickerTarget, setExercisePickerTarget] = useState(null)
|
||||
const [planningPeekExerciseId, setPlanningPeekExerciseId] = useState(null)
|
||||
const [planningPeekCtx, setPlanningPeekCtx] = useState(null)
|
||||
|
||||
const today = new Date().toISOString().split('T')[0]
|
||||
const thirtyDaysLater = new Date(Date.now() + 30 * 24 * 60 * 60 * 1000).toISOString().split('T')[0]
|
||||
@@ -718,11 +741,17 @@ function TrainingPlanningPage() {
|
||||
sections: updater(prev.sections),
|
||||
}))
|
||||
}
|
||||
onRequestExercisePick={({ sectionIndex, itemIndex }) => {
|
||||
setExercisePickerTarget({ sIdx: sectionIndex, iIdx: itemIndex })
|
||||
onRequestExercisePick={({ sectionIndex, itemIndex, multi }) => {
|
||||
setExercisePickerTarget({
|
||||
sIdx: sectionIndex,
|
||||
iIdx: typeof itemIndex === 'number' ? itemIndex : undefined,
|
||||
multi: !!multi,
|
||||
})
|
||||
setExercisePickerOpen(true)
|
||||
}}
|
||||
onPeekExercise={(id) => setPlanningPeekExerciseId(id)}
|
||||
onPeekExercise={(id, variantId) =>
|
||||
setPlanningPeekCtx({ exerciseId: id, variantId: variantId ?? null })
|
||||
}
|
||||
showExecutionExtras={!!editingUnit}
|
||||
/>
|
||||
|
||||
@@ -826,13 +855,39 @@ function TrainingPlanningPage() {
|
||||
)}
|
||||
<ExercisePickerModal
|
||||
open={exercisePickerOpen}
|
||||
multiSelect={!!exercisePickerTarget?.multi}
|
||||
onClose={() => {
|
||||
setExercisePickerOpen(false)
|
||||
setExercisePickerTarget(null)
|
||||
}}
|
||||
onSelectExercise={(ex) => {
|
||||
if (!exercisePickerTarget) return
|
||||
onSelectExercises={
|
||||
exercisePickerTarget?.multi
|
||||
? async (picked) => {
|
||||
if (!exercisePickerTarget || !picked?.length) return
|
||||
const { sIdx } = exercisePickerTarget
|
||||
const rows = []
|
||||
for (const ex of picked) {
|
||||
const row = await hydrateExerciseForPickerRow(ex)
|
||||
if (row) rows.push(row)
|
||||
}
|
||||
if (!rows.length) return
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
sections: prev.sections.map((s, si) =>
|
||||
si !== sIdx ? s : { ...s, items: [...(s.items || []), ...rows] }
|
||||
),
|
||||
}))
|
||||
setExercisePickerOpen(false)
|
||||
setExercisePickerTarget(null)
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
onSelectExercise={async (ex) => {
|
||||
if (!exercisePickerTarget || exercisePickerTarget.multi) return
|
||||
const row = await hydrateExerciseForPickerRow(ex)
|
||||
if (!row) return
|
||||
const { sIdx, iIdx } = exercisePickerTarget
|
||||
if (typeof iIdx !== 'number') return
|
||||
setFormData((prev) => ({
|
||||
...prev,
|
||||
sections: prev.sections.map((s, si) =>
|
||||
@@ -840,30 +895,31 @@ function TrainingPlanningPage() {
|
||||
? s
|
||||
: {
|
||||
...s,
|
||||
items: s.items.map((row, ii) =>
|
||||
items: s.items.map((r2, ii) =>
|
||||
ii !== iIdx
|
||||
? row
|
||||
: row.item_type !== 'exercise'
|
||||
? row
|
||||
? r2
|
||||
: r2.item_type !== 'exercise'
|
||||
? r2
|
||||
: {
|
||||
...row,
|
||||
exercise_id: ex.id,
|
||||
exercise_variant_id: '',
|
||||
exercise_title: ex.title || '',
|
||||
variants: Array.isArray(ex.variants) ? ex.variants : [],
|
||||
...r2,
|
||||
exercise_id: row.exercise_id,
|
||||
exercise_variant_id: row.exercise_variant_id,
|
||||
exercise_title: row.exercise_title,
|
||||
variants: row.variants,
|
||||
}
|
||||
)
|
||||
),
|
||||
}
|
||||
)
|
||||
),
|
||||
}))
|
||||
setExercisePickerOpen(false)
|
||||
setExercisePickerTarget(null)
|
||||
}}
|
||||
/>
|
||||
<ExercisePeekModal
|
||||
open={planningPeekExerciseId != null}
|
||||
exerciseId={planningPeekExerciseId}
|
||||
onClose={() => setPlanningPeekExerciseId(null)}
|
||||
open={planningPeekCtx != null}
|
||||
exerciseId={planningPeekCtx?.exerciseId}
|
||||
variantId={planningPeekCtx?.variantId ?? undefined}
|
||||
onClose={() => setPlanningPeekCtx(null)}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user