Plany: akcje tygodnia (kopiuj/wyczysc) w menu kontekstowym kafelka, odstep miedzy naglowkiem a trescia

This commit is contained in:
tisachi
2026-10-11 19:11:03 +02:00
parent a759bcd673
commit fa325b51af
3 changed files with 54 additions and 19 deletions

View File

@@ -1,5 +1,5 @@
import { useState, type ReactNode } from 'react';
import { Copy, Pencil, Trash2 } from 'lucide-react';
import { Copy, MoreHorizontal, 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). */
@@ -9,10 +9,9 @@ export interface CopySource {
summary: string;
}
/* Panel tygodnia (zamiast akordeonu): nagłówek z badge podsumowania + akcje,
treść zawsze widoczna — przełączanie tygodni odbywa się przez zakładki.
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). */
/* Panel tygodnia (zamiast akordeonu): nagłówek z badge podsumowania + menu „⋯”
(Kopiuj z… / Wyczyść), treść zawsze widoczna — przełączanie tygodni przez zakładki.
Własna nazwa tygodnia: click-to-edit na nagłówku (bez stale widocznego inputa). */
export function WeekPanel({
index,
summary,
@@ -35,6 +34,7 @@ export function WeekPanel({
children: ReactNode;
}) {
const [copyOpen, setCopyOpen] = useState(false);
const [menuOpen, setMenuOpen] = useState(false);
const [editing, setEditing] = useState(false);
const [draft, setDraft] = useState('');
const name = customName.trim();
@@ -90,22 +90,55 @@ export function WeekPanel({
)}
</H2>
<Badge color={summary.color}>{summary.text}</Badge>
<div className="flex items-center flex-wrap gap-2 sm:ml-auto">
{copySources.length > 0 && (
<Button variant="secondary" size="sm" onClick={() => setCopyOpen(true)}>
<Copy className="w-4 h-4" />
Kopiuj z…
{(copySources.length > 0 || canClear) && (
<div className="relative sm:ml-auto">
<Button
variant="ghost"
size="sm"
aria-label="Akcje tygodnia"
aria-haspopup="true"
aria-expanded={menuOpen}
onClick={() => setMenuOpen((o) => !o)}
>
<MoreHorizontal className="w-4 h-4" />
</Button>
)}
{canClear && (
<Button variant="secondary" size="sm" onClick={onClear}>
<Trash2 className="w-4 h-4" />
Wyczyść
</Button>
)}
</div>
{menuOpen && (
<>
<div className="fixed inset-0 z-40" onClick={() => setMenuOpen(false)} />
<div className="absolute right-0 top-full z-50 mt-1 min-w-48 rounded-xl border border-line bg-card p-1.5 shadow-lg">
{copySources.length > 0 && (
<button
type="button"
onClick={() => {
setMenuOpen(false);
setCopyOpen(true);
}}
className="flex w-full cursor-pointer items-center gap-2.5 rounded-lg px-2.5 py-2 text-left text-[0.9rem] font-semibold text-ink transition-colors hover:bg-line/30"
>
<Copy className="w-4 h-4 text-dim" />
Kopiuj z…
</button>
)}
{canClear && (
<button
type="button"
onClick={() => {
setMenuOpen(false);
onClear();
}}
className="flex w-full cursor-pointer items-center gap-2.5 rounded-lg px-2.5 py-2 text-left text-[0.9rem] font-semibold text-danger transition-colors hover:bg-danger/10"
>
<Trash2 className="w-4 h-4" />
Wyczyść
</button>
)}
</div>
</>
)}
</div>
)}
</div>
<div>{children}</div>
<div className="mt-4">{children}</div>
<Modal open={copyOpen} onClose={() => setCopyOpen(false)} title="Kopiuj dni tygodnia" handle>
<p className="mb-3 text-dim text-[0.875rem]">

View File

@@ -448,6 +448,7 @@ describe('PlanEditor — data startu i menu kontekstowe', () => {
// tydzień 4: kopiuj z tygodnia 2 (źródło nie jest poprzednie względem celu)
await user.click(screen.getByRole('button', { name: /Tydzień 4/ }));
await user.click(screen.getByRole('button', { name: 'Akcje tygodnia' }));
await user.click(screen.getByRole('button', { name: 'Kopiuj z…' }));
expect(screen.getByText('2 dni · 1 ćwiczenie')).toBeInTheDocument();
expect(screen.queryByRole('button', { name: 'Kopiuj: Tydzień 4' })).not.toBeInTheDocument();

View File

@@ -128,6 +128,7 @@ test('kopiowanie dni z dowolnego tygodnia („Kopiuj z…”)', async ({ page })
// tydzień 4: kopiuj z tygodnia 2 (źródło nie jest poprzednie względem celu)
await page.getByRole('button', { name: 'Tydzień 4' }).click();
await page.getByRole('button', { name: 'Akcje tygodnia' }).click();
await page.getByRole('button', { name: 'Kopiuj z…' }).click();
const dialog = page.getByRole('dialog');
await expect(dialog.getByText('2 dni · 1 ćwiczenie')).toBeVisible();