Plany: nazwa tygodnia jako click-to-edit na naglowku (bez stale widocznego inputa), alias widoczny w zakladce
This commit is contained in:
@@ -451,8 +451,14 @@ export default function PlanEditor() {
|
||||
id: String(wi),
|
||||
label: (
|
||||
<span className="inline-flex items-center gap-1.5">
|
||||
<span className="sm:hidden">T.{wi + 1}</span>
|
||||
<span className="hidden sm:inline">Tydzień {wi + 1}</span>
|
||||
{w.customName.trim() ? (
|
||||
<span className="max-w-[10rem] truncate">{w.customName.trim()}</span>
|
||||
) : (
|
||||
<>
|
||||
<span className="sm:hidden">T.{wi + 1}</span>
|
||||
<span className="hidden sm:inline">Tydzień {wi + 1}</span>
|
||||
</>
|
||||
)}
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className={cn(
|
||||
|
||||
@@ -1,15 +1,6 @@
|
||||
import { useState, type ReactNode } from 'react';
|
||||
import { Copy, Trash2 } from 'lucide-react';
|
||||
import {
|
||||
Badge,
|
||||
Button,
|
||||
Card,
|
||||
Field,
|
||||
H2,
|
||||
Input,
|
||||
Modal,
|
||||
type BadgeColor,
|
||||
} from '../../../components/ui';
|
||||
import { Copy, Pencil, Trash2 } from 'lucide-react';
|
||||
import { Badge, Button, Card, H2, Modal, type BadgeColor } from '../../../components/ui';
|
||||
|
||||
/** Źródło kopiowania dni: dowolny inny tydzień (z podsumowaniem jego treści). */
|
||||
export interface CopySource {
|
||||
@@ -20,7 +11,7 @@ export interface CopySource {
|
||||
|
||||
/* Panel tygodnia (zamiast akordeonu): nagłówek z badge podsumowania + akcje,
|
||||
treść zawsze widoczna — przełączanie tygodni odbywa się przez zakładki.
|
||||
Nazwa tygodnia należy do tego panelu (edycja zawsze dotyczy wyświetlanego tygodnia).
|
||||
Własna nazwa tygodnia: click-to-edit na nagłówku (bez stale widocznego inputa).
|
||||
„Kopiuj z…” = wybór dowolnego tygodnia źródłowego (nie tylko poprzedniego). */
|
||||
export function WeekPanel({
|
||||
index,
|
||||
@@ -44,10 +35,60 @@ export function WeekPanel({
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const [copyOpen, setCopyOpen] = useState(false);
|
||||
const [editing, setEditing] = useState(false);
|
||||
const [draft, setDraft] = useState('');
|
||||
const name = customName.trim();
|
||||
|
||||
const startEdit = () => {
|
||||
setDraft(customName);
|
||||
setEditing(true);
|
||||
};
|
||||
const commit = () => {
|
||||
onCustomNameChange(draft.trim());
|
||||
setEditing(false);
|
||||
};
|
||||
// Escape: najpierw cofamy draft — blur po unmountie (jeśli nastąpi) zapisze to samo
|
||||
const cancel = () => {
|
||||
setDraft(customName);
|
||||
setEditing(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<div className="flex flex-wrap items-center gap-x-3 gap-y-2">
|
||||
<H2 className="mb-0">Tydzień {index + 1}</H2>
|
||||
<H2 className="mb-0">
|
||||
{editing ? (
|
||||
<input
|
||||
autoFocus
|
||||
value={draft}
|
||||
onChange={(e) => setDraft(e.target.value)}
|
||||
onFocus={(e) => e.currentTarget.select()}
|
||||
onBlur={commit}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter') commit();
|
||||
if (e.key === 'Escape') cancel();
|
||||
}}
|
||||
placeholder={`Tydzień ${index + 1}`}
|
||||
maxLength={40}
|
||||
aria-label={`Nazwa tygodnia ${index + 1}`}
|
||||
className="w-full max-w-xs rounded-[10px] border border-line bg-input px-2.5 py-0.5 text-[1.25rem] font-bold tracking-[-0.01em] text-ink outline-none focus:border-accent"
|
||||
/>
|
||||
) : (
|
||||
<button
|
||||
type="button"
|
||||
onClick={startEdit}
|
||||
title="Zmień nazwę tygodnia"
|
||||
aria-label={`Zmień nazwę tygodnia ${index + 1}`}
|
||||
className="group inline-flex cursor-pointer items-center gap-1.5"
|
||||
>
|
||||
{name || `Tydzień ${index + 1}`}
|
||||
<Pencil
|
||||
className="h-3.5 w-3.5 text-dim opacity-0 transition-opacity group-hover:opacity-100"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</button>
|
||||
)}
|
||||
</H2>
|
||||
<Badge color={summary.color}>{summary.text}</Badge>
|
||||
<div className="flex items-center flex-wrap gap-2 sm:ml-auto">
|
||||
{copySources.length > 0 && (
|
||||
@@ -64,16 +105,6 @@ export function WeekPanel({
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="mt-3 max-w-sm">
|
||||
<Field label={`Nazwa tygodnia ${index + 1} (opcjonalnie)`}>
|
||||
<Input
|
||||
value={customName}
|
||||
onChange={(e) => onCustomNameChange(e.target.value)}
|
||||
placeholder="np. Deload"
|
||||
maxLength={40}
|
||||
/>
|
||||
</Field>
|
||||
</div>
|
||||
<div>{children}</div>
|
||||
|
||||
<Modal open={copyOpen} onClose={() => setCopyOpen(false)} title="Kopiuj dni tygodnia" handle>
|
||||
|
||||
@@ -275,10 +275,9 @@ describe('PlanEditor — data startu i menu kontekstowe', () => {
|
||||
await user.click(screen.getByRole('button', { name: 'Poniedziałek' }));
|
||||
await user.click(screen.getByRole('button', { name: 'dodaj ćwiczenie…' }));
|
||||
await user.click(await screen.findByRole('option', { name: /Przysiady/ }));
|
||||
const aliasField = screen
|
||||
.getByText('Nazwa tygodnia 1 (opcjonalnie)')
|
||||
.closest('[data-slot="field"]') as HTMLElement;
|
||||
await user.type(within(aliasField).getByRole('textbox'), 'Deload');
|
||||
await user.click(screen.getByRole('button', { name: 'Zmień nazwę tygodnia 1' }));
|
||||
await user.type(screen.getByRole('textbox', { name: 'Nazwa tygodnia 1' }), 'Deload');
|
||||
await user.keyboard('{Enter}');
|
||||
|
||||
// krok 3: podsumowanie — siłownia, alias, „szkic — bez startu”, liczniki
|
||||
await user.click(screen.getByRole('button', { name: 'Dalej' }));
|
||||
|
||||
@@ -47,8 +47,11 @@ test('wizard: 3 kroki — szczegóły (siłownia), ćwiczenia + alias, podsumowa
|
||||
await page.getByRole('button', { name: 'Pon' }).click();
|
||||
await page.getByRole('button', { name: 'dodaj ćwiczenie…' }).click();
|
||||
await page.getByRole('option', { name: /Przysiady/ }).click();
|
||||
const aliasInput = page.getByPlaceholder('np. Deload');
|
||||
// własna nazwa tygodnia: click-to-edit na nagłówku „Tydzień 1”
|
||||
await page.getByRole('button', { name: 'Zmień nazwę tygodnia 1' }).click();
|
||||
const aliasInput = page.getByRole('textbox', { name: 'Nazwa tygodnia 1' });
|
||||
await aliasInput.fill('Deload');
|
||||
await aliasInput.press('Enter');
|
||||
|
||||
// krok 3: podsumowanie — alias, siłownia, liczniki; „Zapisz” tylko tutaj
|
||||
await page.getByRole('button', { name: 'Dalej' }).click();
|
||||
|
||||
@@ -480,10 +480,9 @@ describe('PlanEditor — wizard 3-etapowy (tryb podopiecznego)', () => {
|
||||
await user.click(screen.getByRole('button', { name: 'Poniedziałek' }));
|
||||
await user.click(screen.getByRole('button', { name: 'dodaj ćwiczenie…' }));
|
||||
await user.click(await screen.findByRole('option', { name: /Przysiady/ }));
|
||||
const aliasField = screen
|
||||
.getByText('Nazwa tygodnia 1 (opcjonalnie)')
|
||||
.closest('[data-slot="field"]') as HTMLElement;
|
||||
await user.type(within(aliasField).getByRole('textbox'), 'Deload');
|
||||
await user.click(screen.getByRole('button', { name: 'Zmień nazwę tygodnia 1' }));
|
||||
await user.type(screen.getByRole('textbox', { name: 'Nazwa tygodnia 1' }), 'Deload');
|
||||
await user.keyboard('{Enter}');
|
||||
|
||||
// krok 3: podsumowanie — alias, siłownia, dni i ćwiczenia
|
||||
await user.click(screen.getByRole('button', { name: 'Dalej' }));
|
||||
|
||||
Reference in New Issue
Block a user