Plany: pasek tygodni nad akordeonem (szybkie przeskakiwanie miedzy tygodniami)
This commit is contained in:
@@ -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 <EditorSkeleton />;
|
||||
}
|
||||
@@ -225,78 +232,94 @@ export default function PlanEditor() {
|
||||
showStartWeek={!isEdit}
|
||||
/>
|
||||
|
||||
<WeekStrip
|
||||
count={editor.weeks.length}
|
||||
summaries={editor.weeks.map((w, wi) =>
|
||||
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 (
|
||||
<WeekAccordion
|
||||
<div
|
||||
key={wi}
|
||||
index={wi}
|
||||
summary={summary}
|
||||
expanded={expanded}
|
||||
onToggle={() => 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"
|
||||
>
|
||||
<DayPicker
|
||||
days={days}
|
||||
onToggleDay={(dow) =>
|
||||
days.some((d) => d.dayOfWeek === dow)
|
||||
? editor.removeDay(wi, dow)
|
||||
: editor.addDay(wi, dow)
|
||||
}
|
||||
/>
|
||||
<WeekAccordion
|
||||
index={wi}
|
||||
summary={summary}
|
||||
expanded={expanded}
|
||||
onToggle={() => setExpandedWeek(expanded ? -1 : wi)}
|
||||
canCopy={wi > 0}
|
||||
onCopyPrev={() => editor.copyPrevWeek(wi)}
|
||||
canClear={days.length > 0 || !w.detached}
|
||||
onClear={() => setClearWeekIdx(wi)}
|
||||
>
|
||||
<DayPicker
|
||||
days={days}
|
||||
onToggleDay={(dow) =>
|
||||
days.some((d) => d.dayOfWeek === dow)
|
||||
? editor.removeDay(wi, dow)
|
||||
: editor.addDay(wi, dow)
|
||||
}
|
||||
/>
|
||||
|
||||
{days.length === 0 && (
|
||||
<p className="text-dim mt-3">
|
||||
{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.'}
|
||||
</p>
|
||||
)}
|
||||
{days.length === 0 && (
|
||||
<p className="text-dim mt-3">
|
||||
{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.'}
|
||||
</p>
|
||||
)}
|
||||
|
||||
{days.length > 0 && (
|
||||
<div className="mt-3 divide-y divide-line">
|
||||
{days.map((d, di) => (
|
||||
<DayEditor
|
||||
key={d.dayOfWeek}
|
||||
day={d}
|
||||
weekIndex={wi}
|
||||
dayIndex={di}
|
||||
exerciseName={exerciseName}
|
||||
isTraineeMode={isTraineeMode}
|
||||
exercises={exercises}
|
||||
exercisesLoading={exData === undefined}
|
||||
resultsOpenKey={resultsOpenKey}
|
||||
onToggleResults={(ei) => {
|
||||
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);
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</WeekAccordion>
|
||||
{days.length > 0 && (
|
||||
<div className="mt-3 divide-y divide-line">
|
||||
{days.map((d, di) => (
|
||||
<DayEditor
|
||||
key={d.dayOfWeek}
|
||||
day={d}
|
||||
weekIndex={wi}
|
||||
dayIndex={di}
|
||||
exerciseName={exerciseName}
|
||||
isTraineeMode={isTraineeMode}
|
||||
exercises={exercises}
|
||||
exercisesLoading={exData === undefined}
|
||||
resultsOpenKey={resultsOpenKey}
|
||||
onToggleResults={(ei) => {
|
||||
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);
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</WeekAccordion>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
|
||||
|
||||
80
app/src/pages/plans/plan-editor/WeekStrip.tsx
Normal file
80
app/src/pages/plans/plan-editor/WeekStrip.tsx
Normal file
@@ -0,0 +1,80 @@
|
||||
import { useEffect, useRef } from 'react';
|
||||
import type { BadgeColor } from '../../../components/ui';
|
||||
import { cn } from '../../../lib/utils';
|
||||
|
||||
const DOT_COLORS: Record<BadgeColor, string> = {
|
||||
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<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const el = scrollRef.current;
|
||||
const btn = el?.querySelector<HTMLElement>(`[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 (
|
||||
<div className="sticky top-[55px] md:top-[59px] z-20 -mx-4 px-4 md:-mx-8 md:px-8 py-2 bg-bg/95 backdrop-blur">
|
||||
<div
|
||||
ref={scrollRef}
|
||||
role="group"
|
||||
aria-label="Tygodnie planu"
|
||||
className="flex gap-1.5 overflow-x-auto [scrollbar-width:none] [-ms-overflow-style:none] [&::-webkit-scrollbar]:hidden"
|
||||
>
|
||||
{Array.from({ length: count }, (_, wi) => {
|
||||
const summary = summaries[wi];
|
||||
const isActive = active === wi;
|
||||
return (
|
||||
<button
|
||||
key={wi}
|
||||
type="button"
|
||||
data-week-id={wi}
|
||||
aria-pressed={isActive}
|
||||
title={summary?.text}
|
||||
onClick={() => onSelect(wi)}
|
||||
className={cn(
|
||||
'flex h-9 shrink-0 items-center gap-1.5 whitespace-nowrap rounded-full border px-3 text-[0.8125rem] font-semibold cursor-pointer transition-colors',
|
||||
isActive
|
||||
? 'bg-accent text-accent-ink border-accent'
|
||||
: 'bg-card border-line text-dim hover:border-accent hover:text-accent-text',
|
||||
)}
|
||||
>
|
||||
<span className="sm:hidden">T.{wi + 1}</span>
|
||||
<span className="hidden sm:inline">Tydzień {wi + 1}</span>
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className={cn('h-2 w-2 rounded-full', DOT_COLORS[summary?.color ?? 'gray'])}
|
||||
/>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user