diff --git a/app/src/pages/plans/PlanEditor.tsx b/app/src/pages/plans/PlanEditor.tsx index 234abef..4c287bd 100644 --- a/app/src/pages/plans/PlanEditor.tsx +++ b/app/src/pages/plans/PlanEditor.tsx @@ -1,4 +1,4 @@ -import { useEffect, useMemo, useState } from 'react'; +import { useEffect, useMemo, useRef, useState } from 'react'; import { useNavigate, useParams } from 'react-router-dom'; import { createPlan, @@ -27,6 +27,7 @@ import { displayedDaysOf, type EditorDay, type EditorWeek } from './plan-editor/ import { usePlanEditorState } from './plan-editor/usePlanEditorState'; import { PlanMetaForm } from './plan-editor/PlanMetaForm'; import { WeekAccordion } from './plan-editor/WeekAccordion'; +import { WeekStrip } from './plan-editor/WeekStrip'; import { DayPicker } from './plan-editor/DayPicker'; import { DayEditor } from './plan-editor/DayEditor'; @@ -205,6 +206,12 @@ export default function PlanEditor() { const exerciseName = (eid: string) => exercises.find((p) => p.id === eid)?.name ?? eid; + const weekRefs = useRef<(HTMLDivElement | null)[]>([]); + const selectWeek = (wi: number) => { + setExpandedWeek(wi); + weekRefs.current[wi]?.scrollIntoView({ behavior: 'smooth', block: 'start' }); + }; + if (loading) { return ; } @@ -225,78 +232,94 @@ export default function PlanEditor() { showStartWeek={!isEdit} /> + + weekSummary(wi, w, displayedDaysOf(editor.weeks, wi)), + )} + active={expandedWeek} + onSelect={selectWeek} + /> + {editor.weeks.map((w, wi) => { const days = displayedDaysOf(editor.weeks, wi); const summary = weekSummary(wi, w, days); const expanded = expandedWeek === wi; return ( - setExpandedWeek(expanded ? -1 : wi)} - canCopy={wi > 0} - onCopyPrev={() => editor.copyPrevWeek(wi)} - canClear={days.length > 0 || !w.detached} - onClear={() => setClearWeekIdx(wi)} + ref={(el) => { + weekRefs.current[wi] = el; + }} + className="scroll-mt-28" > - - days.some((d) => d.dayOfWeek === dow) - ? editor.removeDay(wi, dow) - : editor.addDay(wi, dow) - } - /> + setExpandedWeek(expanded ? -1 : wi)} + canCopy={wi > 0} + onCopyPrev={() => editor.copyPrevWeek(wi)} + canClear={days.length > 0 || !w.detached} + onClear={() => setClearWeekIdx(wi)} + > + + days.some((d) => d.dayOfWeek === dow) + ? editor.removeDay(wi, dow) + : editor.addDay(wi, dow) + } + /> - {days.length === 0 && ( -

- {wi === 0 - ? 'Wybierz dni treningowe powyżej — pozostałe tygodnie będą je odzwierciedlać.' - : w.detached - ? 'Tydzień wolny (przerwa) — pozostanie pusty.' - : 'Odzwierciedla tydzień 1. Kliknij dzień, aby edytować niezależnie.'} -

- )} + {days.length === 0 && ( +

+ {wi === 0 + ? 'Wybierz dni treningowe powyżej — pozostałe tygodnie będą je odzwierciedlać.' + : w.detached + ? 'Tydzień wolny (przerwa) — pozostanie pusty.' + : 'Odzwierciedla tydzień 1. Kliknij dzień, aby edytować niezależnie.'} +

+ )} - {days.length > 0 && ( -
- {days.map((d, di) => ( - { - const key = `${wi}:${di}:${ei}`; - setResultsOpenKey(resultsOpenKey === key ? null : key); - }} - onAddExercise={(exerciseId) => editor.addExercise(wi, di, exerciseId)} - onRemoveExercise={(ei) => editor.removeExercise(wi, di, ei)} - onMoveExercise={(ei, dir) => editor.moveExercise(wi, di, ei, dir)} - onSetField={(ei, si, field, value) => - editor.setSetField(wi, di, ei, si, field, value) - } - onAddSet={(ei) => editor.addSet(wi, di, ei)} - onRemoveSet={(ei, si) => editor.removeSet(wi, di, ei, si)} - onDuplicateSet={(ei, si) => editor.duplicateSet(wi, di, ei, si)} - latestByExercise={latestByExercise} - progressByExercise={progressByExercise} - onPrefill={(ei) => { - const latest = latestByExercise.get(d.exercises[ei].exerciseId); - if (latest) editor.prefillExercise(wi, di, ei, latest); - }} - /> - ))} -
- )} -
+ {days.length > 0 && ( +
+ {days.map((d, di) => ( + { + const key = `${wi}:${di}:${ei}`; + setResultsOpenKey(resultsOpenKey === key ? null : key); + }} + onAddExercise={(exerciseId) => editor.addExercise(wi, di, exerciseId)} + onRemoveExercise={(ei) => editor.removeExercise(wi, di, ei)} + onMoveExercise={(ei, dir) => editor.moveExercise(wi, di, ei, dir)} + onSetField={(ei, si, field, value) => + editor.setSetField(wi, di, ei, si, field, value) + } + onAddSet={(ei) => editor.addSet(wi, di, ei)} + onRemoveSet={(ei, si) => editor.removeSet(wi, di, ei, si)} + onDuplicateSet={(ei, si) => editor.duplicateSet(wi, di, ei, si)} + latestByExercise={latestByExercise} + progressByExercise={progressByExercise} + onPrefill={(ei) => { + const latest = latestByExercise.get(d.exercises[ei].exerciseId); + if (latest) editor.prefillExercise(wi, di, ei, latest); + }} + /> + ))} +
+ )} +
+ ); })} diff --git a/app/src/pages/plans/plan-editor/WeekStrip.tsx b/app/src/pages/plans/plan-editor/WeekStrip.tsx new file mode 100644 index 0000000..a4d17ce --- /dev/null +++ b/app/src/pages/plans/plan-editor/WeekStrip.tsx @@ -0,0 +1,80 @@ +import { useEffect, useRef } from 'react'; +import type { BadgeColor } from '../../../components/ui'; +import { cn } from '../../../lib/utils'; + +const DOT_COLORS: Record = { + green: 'bg-accent', + gray: 'bg-dim/50', + red: 'bg-danger', + yellow: 'bg-warn', + blue: 'bg-info', +}; + +/** + * Pasek tygodni nad akordeonem (sticky pod topbarem): poziomy scroll chipów + * „Tydzień 1…N” z kropką statusu; aktywny chip wycentrowany (wzór Tabs). + * Mobile: skrócone etykiety „T.1…T.N”. + */ +export function WeekStrip({ + count, + summaries, + active, + onSelect, +}: { + count: number; + summaries: { text: string; color: BadgeColor }[]; + active: number; + onSelect: (wi: number) => void; +}) { + const scrollRef = useRef(null); + + useEffect(() => { + const el = scrollRef.current; + const btn = el?.querySelector(`[data-week-id="${active}"]`); + if (!el || !btn) return; + const br = btn.getBoundingClientRect(); + const er = el.getBoundingClientRect(); + const target = el.scrollLeft + (br.left - er.left) + br.width / 2 - er.width / 2; + const clamped = Math.max(0, Math.min(el.scrollWidth - el.clientWidth, target)); + if (Math.abs(clamped - el.scrollLeft) > 2) el.scrollTo({ left: clamped, behavior: 'smooth' }); + }, [active, count]); + + return ( +
+
+ {Array.from({ length: count }, (_, wi) => { + const summary = summaries[wi]; + const isActive = active === wi; + return ( + + ); + })} +
+
+ ); +} diff --git a/app/test/e2e/plans.spec.ts b/app/test/e2e/plans.spec.ts index 293c7b0..ed3d3c8 100644 --- a/app/test/e2e/plans.spec.ts +++ b/app/test/e2e/plans.spec.ts @@ -49,6 +49,23 @@ test('formularz nowego planu ma wybór tygodnia startu i przycisk „Wstecz” w await expect(page.getByRole('heading', { name: 'Plan e2e' })).toBeVisible(); }); +test('pasek tygodni: klik chipa rozwija dany tydzień', async ({ page }) => { + mockPlans(page); + await login(page); + + await page.getByRole('link', { name: 'Plany' }).click(); + await page.getByRole('button', { name: 'Nowy plan' }).first().click(); + await expect(page.getByRole('heading', { name: 'Nowy plan' })).toBeVisible(); + + // pasek tygodni (4 tygodnie domyślnie) + await expect(page.getByRole('group', { name: 'Tygodnie planu' })).toBeVisible(); + + // klik chipa „Tydzień 3” (w pasku — pierwszy w DOM) → rozwija tydzień 3, zwija 1 + await page.getByRole('button', { name: 'Tydzień 3' }).first().click(); + const dayPickers = page.getByRole('group', { name: 'Dni treningowe' }); + await expect(dayPickers).toHaveCount(1); +}); + test('zmiana kolejności ćwiczeń i kopiowanie serii', async ({ page }) => { mockPlans(page); await login(page); diff --git a/app/test/e2e/trainee-plans.spec.ts b/app/test/e2e/trainee-plans.spec.ts index 3b32acd..77bad83 100644 --- a/app/test/e2e/trainee-plans.spec.ts +++ b/app/test/e2e/trainee-plans.spec.ts @@ -45,8 +45,8 @@ test('zakładka Plany: szkic — akcje Edytuj/Aktywuj/Usuń i struktura inline', await expect(page.getByRole('button', { name: 'Edytuj' })).toBeVisible(); await expect(page.getByRole('button', { name: 'Aktywuj' })).toBeVisible(); await expect(page.getByRole('button', { name: 'Usuń' })).toBeVisible(); - // struktura inline - await expect(page.getByText('Tydzień 1')).toBeVisible(); + // struktura inline (nagłówek akordeonu — pasek tygodni ma też chip „Tydzień 1”) + await expect(page.getByRole('heading', { name: 'Tydzień 1' })).toBeVisible(); await expect(page.getByText('Poniedziałek')).toBeVisible(); await expect(page.getByText(/Przysiady/)).toBeVisible(); }); diff --git a/app/test/trainee-plans.test.tsx b/app/test/trainee-plans.test.tsx index c85eac0..d610c5e 100644 --- a/app/test/trainee-plans.test.tsx +++ b/app/test/trainee-plans.test.tsx @@ -309,8 +309,8 @@ describe('Zakładka „Plany" w panelu podopiecznego', () => { expect(await screen.findByRole('button', { name: 'Edytuj' })).toBeInTheDocument(); expect(screen.getByRole('button', { name: 'Aktywuj' })).toBeInTheDocument(); expect(screen.getByRole('button', { name: 'Usuń' })).toBeInTheDocument(); - // struktura inline - expect(screen.getByText('Tydzień 1')).toBeInTheDocument(); + // struktura inline (nagłówek akordeonu — pasek tygodni ma też chip „Tydzień 1”) + expect(screen.getByRole('heading', { name: 'Tydzień 1' })).toBeInTheDocument(); expect(screen.getByText('Poniedziałek')).toBeInTheDocument(); expect(screen.getByText(/Przysiady/)).toBeInTheDocument(); });