Deploy Development / deploy (push) Failing after 24s
Test Suite / pytest-backend (push) Successful in 34s
Test Suite / lint-backend (push) Successful in 0s
Test Suite / build-frontend (push) Failing after 7s
Test Suite / k6 /health Baseline (push) Successful in 34s
Test Suite / playwright-tests (push) Successful in 1m22s
- Replaced `PageReturnLink` with `PageReturnButton` for consistent back navigation across various pages. - Updated multiple components, including `ExercisePeekModal`, `PageFormEditorChrome`, and `ExerciseDetailPage`, to utilize the new return context features. - Enhanced CSS styles for the new return button to improve visual consistency. - Improved navigation logic in `TrainingFrameworkProgramEditPage` and `TrainingModuleEditPage` to ensure seamless user experience when navigating back to previous locations.
285 lines
9.3 KiB
React
285 lines
9.3 KiB
React
import React, { useMemo } from 'react'
|
|
import { useNavigate } from 'react-router-dom'
|
|
import NavStateLink from '../NavStateLink'
|
|
import {
|
|
buildExercisesListReturnContext,
|
|
navigateWithAppReturn,
|
|
} from '../../utils/navReturnContext'
|
|
import {
|
|
Eye,
|
|
Pencil,
|
|
Trash2,
|
|
Globe,
|
|
Users,
|
|
Lock,
|
|
CheckCircle2,
|
|
Archive,
|
|
CircleDot,
|
|
FilePenLine,
|
|
Image,
|
|
Layers,
|
|
} from 'lucide-react'
|
|
import ExerciseRichTextBlock from '../ExerciseRichTextBlock'
|
|
import { coerceApiNameList } from '../../utils/sanitizeHtml'
|
|
import { canUserRequestExerciseDelete } from '../../utils/exercisePermissions'
|
|
|
|
const VIS_LABELS = { official: 'Global', club: 'Verein', private: 'Privat' }
|
|
const STATUS_LABELS = {
|
|
draft: 'Entwurf',
|
|
in_review: 'In Prüfung',
|
|
approved: 'Freigegeben',
|
|
archived: 'Archiv',
|
|
}
|
|
|
|
function visibilityLabel(v) {
|
|
return VIS_LABELS[v] || v || '—'
|
|
}
|
|
|
|
function statusLabel(s) {
|
|
return STATUS_LABELS[s] || s || '—'
|
|
}
|
|
|
|
function exerciseFocusNames(ex) {
|
|
const fromApi = coerceApiNameList(ex.focus_area_names)
|
|
if (fromApi.length) return fromApi
|
|
if (ex.focus_area) return [ex.focus_area]
|
|
return []
|
|
}
|
|
|
|
function exerciseCardClassName(exercise, userId) {
|
|
const vis = exercise.visibility || 'private'
|
|
const visKey = vis === 'official' || vis === 'club' || vis === 'private' ? vis : 'private'
|
|
const mine = userId != null && Number(exercise.created_by) === Number(userId)
|
|
return ['card', 'exercise-card', `exercise-card--scope-${visKey}`, mine ? 'exercise-card--mine' : '']
|
|
.filter(Boolean)
|
|
.join(' ')
|
|
}
|
|
|
|
function exerciseVariantCount(exercise) {
|
|
if (typeof exercise?.variant_count === 'number' && Number.isFinite(exercise.variant_count)) {
|
|
return Math.max(0, exercise.variant_count)
|
|
}
|
|
return Array.isArray(exercise?.variants) ? exercise.variants.length : 0
|
|
}
|
|
|
|
function exerciseMediaCount(exercise) {
|
|
if (typeof exercise?.media_count === 'number' && Number.isFinite(exercise.media_count)) {
|
|
return Math.max(0, exercise.media_count)
|
|
}
|
|
return Array.isArray(exercise?.media) ? exercise.media.length : 0
|
|
}
|
|
|
|
function ExerciseCardContentStats({ exercise }) {
|
|
const mediaCount = exerciseMediaCount(exercise)
|
|
const variantCount = exerciseVariantCount(exercise)
|
|
if (mediaCount <= 0 && variantCount <= 0) return null
|
|
|
|
const mediaLabel =
|
|
mediaCount === 1 ? '1 Medium hinterlegt' : `${mediaCount} Medien hinterlegt`
|
|
const variantLabel =
|
|
variantCount === 1 ? '1 Variante' : `${variantCount} Varianten`
|
|
|
|
return (
|
|
<div className="exercise-card__content-stats">
|
|
{mediaCount > 0 ? (
|
|
<span className="exercise-card__stat" title={mediaLabel} aria-label={mediaLabel}>
|
|
<Image size={15} strokeWidth={2} aria-hidden />
|
|
<span className="exercise-card__stat-num" aria-hidden>
|
|
{mediaCount}
|
|
</span>
|
|
</span>
|
|
) : null}
|
|
{variantCount > 0 ? (
|
|
<span className="exercise-card__stat" title={variantLabel} aria-label={variantLabel}>
|
|
<Layers size={15} strokeWidth={2} aria-hidden />
|
|
<span className="exercise-card__stat-num" aria-hidden>
|
|
{variantCount}
|
|
</span>
|
|
</span>
|
|
) : null}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
function ExerciseCardScopeStatus({ exercise }) {
|
|
const v = exercise.visibility || 'private'
|
|
const s = exercise.status || 'draft'
|
|
const visLabel = visibilityLabel(v)
|
|
const stLabel = statusLabel(s)
|
|
const tip = `${visLabel} · ${stLabel}`
|
|
let VisIcon = Lock
|
|
if (v === 'official') VisIcon = Globe
|
|
else if (v === 'club') VisIcon = Users
|
|
let StatIcon = FilePenLine
|
|
if (s === 'approved') StatIcon = CheckCircle2
|
|
else if (s === 'archived') StatIcon = Archive
|
|
else if (s === 'in_review') StatIcon = CircleDot
|
|
return (
|
|
<div
|
|
className="exercise-card__meta-compact"
|
|
title={tip}
|
|
aria-label={`Sichtbarkeit: ${visLabel}. Status: ${stLabel}.`}
|
|
>
|
|
<span className="exercise-card__meta-glyph">
|
|
<VisIcon size={15} strokeWidth={2} aria-hidden />
|
|
</span>
|
|
<span className="exercise-card__meta-sep" aria-hidden>
|
|
·
|
|
</span>
|
|
<span className="exercise-card__meta-glyph">
|
|
<StatIcon size={15} strokeWidth={2} aria-hidden />
|
|
</span>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
/**
|
|
* Kartenzeile in der Übungsliste (Fokus/Planung — keine Virtualisierung im Grid, dafür content-visibility in app.css).
|
|
*/
|
|
export default function ExerciseListCard({
|
|
exercise,
|
|
user,
|
|
selectedIds,
|
|
toggleSelect,
|
|
onDelete,
|
|
onPeek,
|
|
selectionPinned = false,
|
|
}) {
|
|
const navigate = useNavigate()
|
|
const listReturn = useMemo(() => buildExercisesListReturnContext(), [])
|
|
const focusNames = exerciseFocusNames(exercise)
|
|
const styleNames = coerceApiNameList(exercise.style_direction_names)
|
|
const typeNames = coerceApiNameList(exercise.training_type_names)
|
|
const titleText = (exercise.title || 'Übung').replace(/"/g, '')
|
|
|
|
const openExercisePage = () =>
|
|
navigateWithAppReturn(navigate, `/exercises/${exercise.id}`, listReturn)
|
|
|
|
const handleBodyClick = (e) => {
|
|
if (e.target.closest('a, button, input, textarea, select, label, [role="button"]')) return
|
|
openExercisePage()
|
|
}
|
|
|
|
const handleBodyKeyDown = (e) => {
|
|
if (e.key !== 'Enter' && e.key !== ' ') return
|
|
if (e.target.closest('a, button, input, textarea, select, label, [role="button"]')) return
|
|
e.preventDefault()
|
|
openExercisePage()
|
|
}
|
|
|
|
return (
|
|
<div
|
|
className={[
|
|
exerciseCardClassName(exercise, user?.id),
|
|
selectionPinned ? 'exercise-card--selection-pinned' : '',
|
|
]
|
|
.filter(Boolean)
|
|
.join(' ')}
|
|
>
|
|
<div className="exercise-card-layout exercise-card-layout--grow">
|
|
<input
|
|
type="checkbox"
|
|
checked={selectedIds.has(Number(exercise.id))}
|
|
onChange={() => toggleSelect(exercise)}
|
|
aria-label={`„${titleText}“ auswählen`}
|
|
className="exercise-card-layout__check"
|
|
/>
|
|
<div
|
|
className="exercise-card__body exercise-card-body-flex exercise-card__body--clickable"
|
|
role="link"
|
|
tabIndex={0}
|
|
onClick={handleBodyClick}
|
|
onKeyDown={handleBodyKeyDown}
|
|
aria-label={`„${titleText}“ öffnen`}
|
|
>
|
|
<h3 className="exercise-card-title">
|
|
<NavStateLink
|
|
to={`/exercises/${exercise.id}`}
|
|
returnContext={listReturn}
|
|
onClick={(e) => e.stopPropagation()}
|
|
>
|
|
{exercise.title}
|
|
</NavStateLink>
|
|
{selectionPinned ? (
|
|
<span className="exercise-card__selection-badge" title="In Modul-Auswahl">
|
|
Auswahl
|
|
</span>
|
|
) : null}
|
|
</h3>
|
|
<div className="exercise-card-tags">
|
|
{focusNames.map((name) => (
|
|
<span key={`fa:${name}`} className="exercise-tag exercise-tag--accent">
|
|
{name}
|
|
</span>
|
|
))}
|
|
{styleNames.map((name) => (
|
|
<span key={`sd:${name}`} className="exercise-tag exercise-tag--style">
|
|
{name}
|
|
</span>
|
|
))}
|
|
{typeNames.map((name) => (
|
|
<span key={`tt:${name}`} className="exercise-tag exercise-tag--training">
|
|
{name}
|
|
</span>
|
|
))}
|
|
{(exercise.exercise_kind || '').toLowerCase().trim() === 'combination' ? (
|
|
<span
|
|
className="exercise-tag"
|
|
style={{ background: 'var(--accent-soft)', color: 'var(--accent-dark)' }}
|
|
>
|
|
Kombination
|
|
</span>
|
|
) : null}
|
|
</div>
|
|
{exercise.summary && String(exercise.summary).trim() ? (
|
|
<div className="exercise-card-summary exercise-card-summary--rich">
|
|
<ExerciseRichTextBlock
|
|
html={exercise.summary}
|
|
exerciseId={exercise.id}
|
|
media={exercise.media || []}
|
|
/>
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
<div className="exercise-card__footer">
|
|
<div className="exercise-card__footer-meta">
|
|
<ExerciseCardScopeStatus exercise={exercise} />
|
|
<ExerciseCardContentStats exercise={exercise} />
|
|
</div>
|
|
<div className="exercise-card__actions exercise-card__actions--icons">
|
|
<button
|
|
type="button"
|
|
className="exercise-card__icon-btn"
|
|
title="Vorschau"
|
|
aria-label={`„${titleText}“ in Vorschau anzeigen`}
|
|
onClick={() => onPeek?.(exercise)}
|
|
>
|
|
<Eye size={18} strokeWidth={2} aria-hidden />
|
|
</button>
|
|
<NavStateLink
|
|
to={`/exercises/${exercise.id}/edit`}
|
|
returnContext={listReturn}
|
|
className="exercise-card__icon-btn"
|
|
title="Bearbeiten"
|
|
aria-label={`„${titleText}“ bearbeiten`}
|
|
>
|
|
<Pencil size={18} strokeWidth={2} aria-hidden />
|
|
</NavStateLink>
|
|
{canUserRequestExerciseDelete(user, exercise) ? (
|
|
<button
|
|
type="button"
|
|
className="exercise-card__icon-btn exercise-card__icon-btn--danger"
|
|
title="Löschen"
|
|
aria-label={`„${(exercise.title || 'Übung').replace(/"/g, '')}“ löschen`}
|
|
onClick={() => onDelete(exercise)}
|
|
>
|
|
<Trash2 size={18} strokeWidth={2} aria-hidden />
|
|
</button>
|
|
) : null}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|