Refactor navigation components and enhance return context handling
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
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.
This commit is contained in:
1 parent
6e6270b717
commit
4588ef4c7e
28 files changed
+497
-190
No files matched your search
@@ -5,6 +5,7 @@
|
||||
import React, { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import api from '../utils/api'
|
||||
import NavStateLink from './NavStateLink'
|
||||
import ExerciseRichTextBlock from './ExerciseRichTextBlock'
|
||||
import CombinationPlanBracket from './CombinationPlanBracket'
|
||||
import { effectiveComboMethodProfile } from '../utils/comboPlanningMethodProfile'
|
||||
@@ -36,6 +37,8 @@ export default function ExercisePeekModal({
|
||||
titleFallback,
|
||||
/** Nur Planung: effektives method_profile aus Zeilen-Katalog + Planungs-Override */
|
||||
peekExtras,
|
||||
/** Rücksprung-Kontext für „Vollständige Übungsseite“ */
|
||||
returnContext,
|
||||
}) {
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [err, setErr] = useState(null)
|
||||
@@ -255,13 +258,24 @@ export default function ExercisePeekModal({
|
||||
</div>
|
||||
{top?.exerciseId != null ? (
|
||||
<div style={{ padding: '0 1rem 1rem', flexShrink: 0 }}>
|
||||
<Link
|
||||
to={`/exercises/${top.exerciseId}`}
|
||||
className="btn btn-secondary"
|
||||
style={{ width: '100%', textDecoration: 'none', textAlign: 'center', display: 'block' }}
|
||||
>
|
||||
Vollständige Übungsseite öffnen
|
||||
</Link>
|
||||
{returnContext ? (
|
||||
<NavStateLink
|
||||
to={`/exercises/${top.exerciseId}`}
|
||||
returnContext={returnContext}
|
||||
className="btn btn-secondary"
|
||||
style={{ width: '100%', textDecoration: 'none', textAlign: 'center', display: 'block' }}
|
||||
>
|
||||
Vollständige Übungsseite öffnen
|
||||
</NavStateLink>
|
||||
) : (
|
||||
<Link
|
||||
to={`/exercises/${top.exerciseId}`}
|
||||
className="btn btn-secondary"
|
||||
style={{ width: '100%', textDecoration: 'none', textAlign: 'center', display: 'block' }}
|
||||
>
|
||||
Vollständige Übungsseite öffnen
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import React from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { linkStateWithAppReturn } from '../utils/navReturnContext'
|
||||
|
||||
/** Router-Link mit appReturn im State (Rücksprung vom Zielscreen). */
|
||||
export default function NavStateLink({ to, returnContext, state, children, ...rest }) {
|
||||
return (
|
||||
<Link to={to} state={linkStateWithAppReturn(returnContext, state)} {...rest}>
|
||||
{children}
|
||||
</Link>
|
||||
)
|
||||
}
|
||||
@@ -1,27 +1,30 @@
|
||||
import React from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { useFormEditorActions } from '../context/FormEditorActionsContext'
|
||||
import PageReturnButton from './PageReturnButton'
|
||||
|
||||
/**
|
||||
* Vollseiten-Editor: Zurück/Titel oben; FormActionBar fix unten (alle Viewports via FormEditorBottomSlot).
|
||||
* Vollseiten-Editor: Zurück-Schalter + Titel oben; FormActionBar fix unten (FormEditorBottomSlot).
|
||||
*/
|
||||
export default function PageFormEditorChrome({
|
||||
title,
|
||||
backTo,
|
||||
backLabel = 'Zurück',
|
||||
fallbackPath,
|
||||
fallbackLabel,
|
||||
actionConfig,
|
||||
children,
|
||||
testId,
|
||||
showReturn = true,
|
||||
}) {
|
||||
useFormEditorActions(actionConfig)
|
||||
|
||||
return (
|
||||
<div className="page-form-editor" data-testid={testId}>
|
||||
<header className="page-form-editor__header">
|
||||
{backTo ? (
|
||||
<Link to={backTo} className="page-form-editor__back">
|
||||
← {backLabel}
|
||||
</Link>
|
||||
{showReturn && fallbackPath && fallbackLabel ? (
|
||||
<PageReturnButton
|
||||
fallbackPath={fallbackPath}
|
||||
fallbackLabel={fallbackLabel}
|
||||
className="page-return-btn page-form-editor__back btn btn-secondary btn-small"
|
||||
/>
|
||||
) : null}
|
||||
<h1 className="page-form-editor__title">{title}</h1>
|
||||
</header>
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import React, { useMemo } from 'react'
|
||||
import { ArrowLeft } from 'lucide-react'
|
||||
import { useNavReturn } from '../hooks/useNavReturn'
|
||||
|
||||
/**
|
||||
* App-typischer Zurück-Schalter (kein Router-Link) — nutzt appReturn / History / Fallback.
|
||||
*/
|
||||
export default function PageReturnButton({
|
||||
fallbackPath,
|
||||
fallbackLabel,
|
||||
className = 'page-return-btn btn btn-secondary btn-small',
|
||||
}) {
|
||||
const fallback = useMemo(
|
||||
() =>
|
||||
fallbackPath && fallbackLabel
|
||||
? { path: fallbackPath, label: fallbackLabel }
|
||||
: null,
|
||||
[fallbackPath, fallbackLabel]
|
||||
)
|
||||
const { goBack, target } = useNavReturn(fallback)
|
||||
|
||||
if (!target?.label) return null
|
||||
|
||||
return (
|
||||
<button type="button" className={className} onClick={goBack} aria-label={target.label}>
|
||||
<ArrowLeft size={16} strokeWidth={2.25} className="page-return-btn__icon" aria-hidden />
|
||||
<span>{target.label}</span>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
import React from 'react'
|
||||
import { useLocation, useNavigate } from 'react-router-dom'
|
||||
import { goNavReturn, resolveNavReturnTarget } from '../utils/navReturnContext'
|
||||
|
||||
/**
|
||||
* Einheitlicher Zurück-Link für Editor-/Detailseiten (PWA-sicher).
|
||||
*/
|
||||
export default function PageReturnLink({
|
||||
fallbackPath,
|
||||
fallbackLabel,
|
||||
className = 'page-return-link',
|
||||
style,
|
||||
}) {
|
||||
const location = useLocation()
|
||||
const navigate = useNavigate()
|
||||
const target = resolveNavReturnTarget(location, {
|
||||
path: fallbackPath,
|
||||
label: fallbackLabel,
|
||||
})
|
||||
|
||||
if (!target?.path || !target?.label) return null
|
||||
|
||||
const handleClick = (e) => {
|
||||
e.preventDefault()
|
||||
goNavReturn(navigate, location, {
|
||||
path: fallbackPath,
|
||||
label: fallbackLabel,
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<a href={target.path} className={className} style={style} onClick={handleClick}>
|
||||
← {target.label}
|
||||
</a>
|
||||
)
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import React, { useEffect, useState, useRef, useMemo, useCallback } from 'react'
|
||||
import { useNavigate, useParams, Link } from 'react-router-dom'
|
||||
import { useNavigate, useParams, Link, useLocation } from 'react-router-dom'
|
||||
import api, { buildExerciseApiPayload } from '../../utils/api'
|
||||
import { resolveExerciseMediaFileUrl, resolveMediaAssetFileUrl } from '../../utils/exerciseMediaUrl'
|
||||
import RichTextEditor from '../RichTextEditor'
|
||||
@@ -27,6 +27,14 @@ import { readSlotProfilesV1, normalizeAdvanceMode, parseComboRepSeriesCountUi }
|
||||
import { GripVertical } from 'lucide-react'
|
||||
import UnsavedChangesPrompt from '../UnsavedChangesPrompt'
|
||||
import PageFormEditorChrome from '../PageFormEditorChrome'
|
||||
import { useNavReturn } from '../../hooks/useNavReturn'
|
||||
import {
|
||||
EXERCISES_LIST_PATH,
|
||||
buildCurrentLocationReturnContext,
|
||||
buildExercisesListReturnContext,
|
||||
linkStateWithAppReturn,
|
||||
preserveAppReturnOnNavigate,
|
||||
} from '../../utils/navReturnContext'
|
||||
import { useBeforeUnloadWhen, useUnsavedChangesBlocker } from '../../hooks/useUnsavedChangesBlocker'
|
||||
|
||||
const INTENSITY_OPTIONS = [
|
||||
@@ -469,6 +477,9 @@ function MultiAssocBlock({ title, rows, setRows, options, idKey, emptyLabel }) {
|
||||
function ExerciseFormPageRoot() {
|
||||
const { id: routeId } = useParams()
|
||||
const navigate = useNavigate()
|
||||
const location = useLocation()
|
||||
const exercisesListReturn = useMemo(() => buildExercisesListReturnContext(), [])
|
||||
const { goBack } = useNavReturn(exercisesListReturn)
|
||||
const { user } = useAuth()
|
||||
const isSuperadmin = user?.role === 'superadmin'
|
||||
const isPlatformAdmin = user?.role === 'admin' || user?.role === 'superadmin'
|
||||
@@ -941,16 +952,16 @@ function ExerciseFormPageRoot() {
|
||||
setVariants((ex.variants || []).map(apiVariantToRow))
|
||||
setFormDirty(false)
|
||||
toast.success('Gespeichert.')
|
||||
if (closeAfter) navigate('/exercises')
|
||||
if (closeAfter) goBack()
|
||||
return true
|
||||
}
|
||||
const created = await api.createExercise(payload)
|
||||
setFormDirty(false)
|
||||
toast.success('Übung angelegt.')
|
||||
if (closeAfter) {
|
||||
navigate('/exercises')
|
||||
goBack()
|
||||
} else if (!fromUnsavedDialog) {
|
||||
navigate(`/exercises/${created.id}/edit`, { replace: true })
|
||||
preserveAppReturnOnNavigate(navigate, location, `/exercises/${created.id}/edit`, { replace: true })
|
||||
}
|
||||
return true
|
||||
} catch (err) {
|
||||
@@ -960,7 +971,7 @@ function ExerciseFormPageRoot() {
|
||||
setSaving(false)
|
||||
}
|
||||
},
|
||||
[exerciseId, formData, isEdit, navigate, toast],
|
||||
[exerciseId, formData, isEdit, navigate, location, toast, goBack],
|
||||
)
|
||||
|
||||
const handleSubmit = useCallback(
|
||||
@@ -979,10 +990,6 @@ function ExerciseFormPageRoot() {
|
||||
[performSaveAttempt],
|
||||
)
|
||||
|
||||
const goBackToList = useCallback(() => {
|
||||
navigate('/exercises')
|
||||
}, [navigate])
|
||||
|
||||
const actionConfig = useMemo(
|
||||
() => ({
|
||||
formId: 'exercise-form',
|
||||
@@ -990,11 +997,11 @@ function ExerciseFormPageRoot() {
|
||||
isNew: !isEdit,
|
||||
onSave: handleSubmit,
|
||||
onSaveAndClose: handleSaveAndClose,
|
||||
onCancel: goBackToList,
|
||||
onCancel: goBack,
|
||||
showSave: true,
|
||||
showSaveAndClose: true,
|
||||
}),
|
||||
[saving, isEdit, handleSubmit, handleSaveAndClose, goBackToList],
|
||||
[saving, isEdit, handleSubmit, handleSaveAndClose, goBack],
|
||||
)
|
||||
|
||||
const handleUnsavedDialogSave = async () => {
|
||||
@@ -1198,15 +1205,17 @@ function ExerciseFormPageRoot() {
|
||||
<PageFormEditorChrome
|
||||
testId="exercise-form-page"
|
||||
title={isEdit ? 'Übung bearbeiten' : 'Neue Übung'}
|
||||
backTo="/exercises"
|
||||
backLabel="Übersicht"
|
||||
fallbackPath={EXERCISES_LIST_PATH}
|
||||
fallbackLabel="Zurück zur Übungsliste"
|
||||
actionConfig={actionConfig}
|
||||
>
|
||||
{isEdit ? (
|
||||
<p style={{ margin: '0 0 12px' }}>
|
||||
<Link
|
||||
to={`/exercises/${exerciseId}`}
|
||||
state={{ fromExerciseEdit: true }}
|
||||
state={linkStateWithAppReturn(
|
||||
buildCurrentLocationReturnContext(location, 'Zurück zur Bearbeitung')
|
||||
)}
|
||||
className="btn btn-secondary"
|
||||
style={{ fontSize: '0.875rem' }}
|
||||
>
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import React from 'react'
|
||||
import { Link, useNavigate } from 'react-router-dom'
|
||||
import React, { useMemo } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import NavStateLink from '../NavStateLink'
|
||||
import {
|
||||
buildExercisesListReturnContext,
|
||||
navigateWithAppReturn,
|
||||
} from '../../utils/navReturnContext'
|
||||
import {
|
||||
Eye,
|
||||
Pencil,
|
||||
@@ -141,12 +146,14 @@ export default function ExerciseListCard({
|
||||
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 = () => navigate(`/exercises/${exercise.id}`)
|
||||
const openExercisePage = () =>
|
||||
navigateWithAppReturn(navigate, `/exercises/${exercise.id}`, listReturn)
|
||||
|
||||
const handleBodyClick = (e) => {
|
||||
if (e.target.closest('a, button, input, textarea, select, label, [role="button"]')) return
|
||||
@@ -186,9 +193,13 @@ export default function ExerciseListCard({
|
||||
aria-label={`„${titleText}“ öffnen`}
|
||||
>
|
||||
<h3 className="exercise-card-title">
|
||||
<Link to={`/exercises/${exercise.id}`} onClick={(e) => e.stopPropagation()}>
|
||||
<NavStateLink
|
||||
to={`/exercises/${exercise.id}`}
|
||||
returnContext={listReturn}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{exercise.title}
|
||||
</Link>
|
||||
</NavStateLink>
|
||||
{selectionPinned ? (
|
||||
<span className="exercise-card__selection-badge" title="In Modul-Auswahl">
|
||||
Auswahl
|
||||
@@ -246,14 +257,15 @@ export default function ExerciseListCard({
|
||||
>
|
||||
<Eye size={18} strokeWidth={2} aria-hidden />
|
||||
</button>
|
||||
<Link
|
||||
<NavStateLink
|
||||
to={`/exercises/${exercise.id}/edit`}
|
||||
returnContext={listReturn}
|
||||
className="exercise-card__icon-btn"
|
||||
title="Bearbeiten"
|
||||
aria-label={`„${(exercise.title || 'Übung').replace(/"/g, '')}“ bearbeiten`}
|
||||
aria-label={`„${titleText}“ bearbeiten`}
|
||||
>
|
||||
<Pencil size={18} strokeWidth={2} aria-hidden />
|
||||
</Link>
|
||||
</NavStateLink>
|
||||
{canUserRequestExerciseDelete(user, exercise) ? (
|
||||
<button
|
||||
type="button"
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import React, { useState, useEffect, useMemo, useCallback, useRef, lazy, Suspense } from 'react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import api from '../../utils/api'
|
||||
import { useAuth } from '../../context/AuthContext'
|
||||
import { activeClubMemberships, getTenantClubDependencyKey } from '../../utils/activeClub'
|
||||
@@ -11,6 +10,7 @@ import ExerciseListSearchBar from './ExerciseListSearchBar'
|
||||
import ExerciseListBulkToolbar from './ExerciseListBulkToolbar'
|
||||
import SaveSelectedExercisesAsModuleModal from './SaveSelectedExercisesAsModuleModal'
|
||||
import ExercisePeekModal from '../ExercisePeekModal'
|
||||
import NavStateLink from '../NavStateLink'
|
||||
import { buildExercisesListReturnContext } from '../../utils/navReturnContext'
|
||||
import { buildExerciseListFilterChips } from '../../utils/exerciseListFilterChips'
|
||||
import { applyDashboardExerciseListUrl, buildExerciseListQueryBase } from '../../utils/exerciseListQuery'
|
||||
@@ -481,9 +481,13 @@ function ExercisesListPageRoot() {
|
||||
<div className="exercises-page__header">
|
||||
<h1 className="page-title exercises-page__title">Übungen</h1>
|
||||
{pageTab === 'list' ? (
|
||||
<Link to="/exercises/new" className="btn btn-primary">
|
||||
<NavStateLink
|
||||
to="/exercises/new"
|
||||
returnContext={exercisesModuleReturnContext}
|
||||
className="btn btn-primary"
|
||||
>
|
||||
+ Neu
|
||||
</Link>
|
||||
</NavStateLink>
|
||||
) : (
|
||||
<span aria-hidden="true" />
|
||||
)}
|
||||
|
||||
@@ -6,6 +6,7 @@ import api from '../../utils/api'
|
||||
import { useToast } from '../../context/ToastContext'
|
||||
import { useAuth } from '../../context/AuthContext'
|
||||
import { activeClubMemberships } from '../../utils/activeClub'
|
||||
import { navigateWithAppReturn } from '../../utils/navReturnContext'
|
||||
|
||||
/**
|
||||
* Übernimmt den gespeicherten Ablauf einer geplanten Trainingseinheit in ein Rahmenprogramm (neu oder bestehend, Slot wählbar).
|
||||
@@ -15,6 +16,7 @@ export default function TrainingPublishToFrameworkModal({
|
||||
onClose,
|
||||
unitId,
|
||||
planningModalClubId,
|
||||
returnContext,
|
||||
onSuccess,
|
||||
}) {
|
||||
const navigate = useNavigate()
|
||||
@@ -131,7 +133,7 @@ export default function TrainingPublishToFrameworkModal({
|
||||
})
|
||||
toast.success('Ablauf wurde im Rahmenprogramm gespeichert.')
|
||||
if (created?.id) {
|
||||
navigate(`/planning/framework-programs/${created.id}`)
|
||||
navigateWithAppReturn(navigate, `/planning/framework-programs/${created.id}`, returnContext)
|
||||
}
|
||||
onSuccess?.()
|
||||
resetAndClose()
|
||||
@@ -177,7 +179,7 @@ export default function TrainingPublishToFrameworkModal({
|
||||
const updated = await api.publishTrainingUnitToFramework(unitId, payload)
|
||||
toast.success('Ablauf wurde im Rahmenprogramm gespeichert.')
|
||||
if (updated?.id) {
|
||||
navigate(`/planning/framework-programs/${updated.id}`)
|
||||
navigateWithAppReturn(navigate, `/planning/framework-programs/${updated.id}`, returnContext)
|
||||
}
|
||||
onSuccess?.()
|
||||
resetAndClose()
|
||||
|
||||
Reference in new issue
Block a user