UI: klikalny caly wiersz dnia z pojedynczym hoverem (koniec z podwojnym podswietleniem dzien+cwiczenie)

This commit is contained in:
Tilumca
2026-10-15 01:42:46 +02:00
parent 27a1507e50
commit ac4ea4ae07
2 changed files with 70 additions and 15 deletions

View File

@@ -3,7 +3,9 @@ import { Link } from 'react-router-dom';
import { Play } from 'lucide-react';
import { fmtDate } from '../../lib/format';
import { DAY_NAMES, DAY_STATUS } from '../../lib/labels';
import { Badge, Button, Card, H2 } from '../ui';
import { Badge, Card, H2 } from '../ui';
import { buttonVariants } from '../ui/button';
import { cn } from '../../lib/utils';
import type { PlanDay, PlanWeek } from '../../api/types';
/* Tło wiersza dnia zależne od statusu. */
@@ -20,20 +22,25 @@ const DAY_DOT: Record<PlanDay['status'], string> = {
SKIPPED: 'bg-danger',
};
/** Wiersz dnia planu (read-only): kropka statusu + nazwa (+ data), akcje, lista ćwiczeń. */
/**
* Wiersz dnia planu (read-only): kropka statusu + nazwa (+ data), akcje, lista ćwiczeń.
* Gdy podano `to` — cały wiersz jest jednym klikalnym linkiem z pojedynczym
* hoverem na całym elemencie (wcześniej nakładały się dwa hovere: dzień + ćwiczenie).
*/
export function PlanDayRow({
day,
showDate = false,
actions,
to,
}: {
day: PlanDay;
showDate?: boolean;
actions?: ReactNode;
to?: string;
}) {
return (
<div
className={`rounded-[10px] px-3 py-3 transition-colors hover:bg-line/20 ${DAY_TINT[day.status]}`.trim()}
>
const base = `rounded-[10px] px-3 py-3 ${DAY_TINT[day.status]}`.trim();
const inner = (
<>
<div className="flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between">
<div className="flex min-w-0 flex-wrap items-center gap-2">
<span
@@ -51,7 +58,7 @@ export function PlanDayRow({
{day.exercises.map((ex) => (
<li
key={ex.id}
className="flex items-center justify-between gap-3 rounded-[10px] px-2 py-1.5 transition-colors hover:bg-line/20"
className="flex items-center justify-between gap-3 rounded-[10px] px-2 py-1.5"
>
<span className="min-w-0 truncate text-[0.875rem]">{ex.exercise.name}</span>
<span className="shrink-0 text-dim text-[0.8125rem] tabular-nums">
@@ -63,11 +70,20 @@ export function PlanDayRow({
</li>
))}
</ul>
</div>
</>
);
if (to) {
return (
<Link to={to} className={cn(base, 'block transition-colors hover:bg-line/20')}>
{inner}
</Link>
);
}
return <div className={base}>{inner}</div>;
}
/** Karta tygodnia planu (read-only): H2 + postęp tygodnia + wiersze dni (badge statusu, „Wykonaj”). */
/** Karta tygodnia planu: H2 + postęp tygodnia + wiersze dni (badge statusu);
* dla aktywnego planu cały wiersz dnia jest linkiem do treningu (chip „Wykonaj”). */
export function PlanWeekCard({
week,
showDate = false,
@@ -113,16 +129,19 @@ export function PlanWeekCard({
key={d.id}
day={d}
showDate={showDate}
to={canExecute ? `/day/${d.id}` : undefined}
actions={
<>
<Badge color={DAY_STATUS[d.status].color}>{DAY_STATUS[d.status].label}</Badge>
{canExecute && d.status === 'PLANNED' && (
<Link to={`/day/${d.id}`}>
<Button size="sm">
<Play className="w-4 h-4" />
Wykonaj
</Button>
</Link>
// wskazówka wizualna — klikalność i nawigacja są na całym wierszu
<span
aria-hidden="true"
className={cn(buttonVariants({ size: 'sm' }), 'pointer-events-none')}
>
<Play className="w-4 h-4" />
Wykonaj
</span>
)}
</>
}

View File

@@ -325,6 +325,42 @@ describe('PlanDetail — udostępnianie planów (WP4)', () => {
});
describe('PlanDetail — statusy i klikalność dni', () => {
it('szkic: wiersz dnia bez linku (dzień klikalny tylko w aktywnym planie)', async () => {
mockApi({}, { user: OWNER, plans: [planDetail()] });
const user = userEvent.setup();
renderApp();
await loginAndOpenPlans(user, OWNER.email);
await user.click(screen.getByRole('link', { name: /Otwórz/ }));
expect(await screen.findByRole('heading', { name: 'Plan masowy' })).toBeInTheDocument();
expect(screen.getByText('Poniedziałek')).toBeInTheDocument();
expect(screen.queryByRole('link', { name: /Poniedziałek/ })).not.toBeInTheDocument();
});
it('plan aktywny: cały dzień to link do /day/:id; tylko „Porzuć” (bez „Wznów”)', async () => {
const active = planDetail({ status: 'ACTIVE', weeksCount: 1, startDate: '2026-10-12' });
mockApi({}, { user: OWNER, plans: [active], plan: active });
const user = userEvent.setup();
renderApp();
await loginAndOpenPlans(user, OWNER.email);
await user.click(screen.getByRole('link', { name: /Otwórz/ }));
expect(await screen.findByRole('heading', { name: 'Plan masowy' })).toBeInTheDocument();
// cały wiersz dnia = jeden link do dnia treningu (pojedynczy hover)
const dayLink = await screen.findByRole('link', { name: /Poniedziałek/ });
expect(dayLink).toHaveAttribute('href', '/day/td-1');
expect(screen.queryByRole('button', { name: 'Wykonaj' })).not.toBeInTheDocument();
const header = document.querySelector('header')!;
expect(within(header).getByRole('button', { name: 'Porzuć' })).toBeInTheDocument();
// dzień PLANNED = plan w trakcie realizacji
expect(
within(header).queryByRole('button', { name: 'Oznacz jako ukończony' }),
).not.toBeInTheDocument();
expect(within(header).queryByRole('button', { name: 'Wznów' })).not.toBeInTheDocument();
});
it('plan ukończony: akcja „Wznów”; potwierdzenie = POST /plans/:id/reopen', async () => {
const capture: Capture = {};
const closed = planDetail({ status: 'COMPLETED' });