diff --git a/app/src/api/queries.ts b/app/src/api/queries.ts index 2f1b552..a2632ab 100644 --- a/app/src/api/queries.ts +++ b/app/src/api/queries.ts @@ -656,6 +656,12 @@ export interface PlanBody { startDate?: string; /** Edycja planu ACTIVE: wymagana notatka audytowa, gdy coś faktycznie się zmienia. */ changeNote?: string; + /** + * Edycja planu ACTIVE: świadoma zgoda na usunięcie dnia z historią treningową. + * Backend soft-remuje taki dzień (removedAt) — historia sesji/serii zostaje, + * dzień znika z planu, kalendarza i statystyk. + */ + forceRemoveDays?: boolean; } export function createPlan(body: PlanBody) { diff --git a/app/src/components/HistoryTable.tsx b/app/src/components/HistoryTable.tsx index fef1d24..5e8d6ee 100644 --- a/app/src/components/HistoryTable.tsx +++ b/app/src/components/HistoryTable.tsx @@ -2,7 +2,7 @@ import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { ChevronDown, ChevronUp, MessageSquare, MessageSquarePlus, Trash2 } from 'lucide-react'; import type { HistorySession } from '../api/types'; -import { fmtDate, fmtDuration, fmtVolume } from '../lib/format'; +import { fmtDate, fmtDuration, fmtLoadKg, fmtVolume } from '../lib/format'; import { localizedName } from '../lib/localizedName'; import { muscleName, SESSION_STATUS } from '../lib/labels'; import { Badge, Button, Textarea } from './ui'; @@ -182,7 +182,7 @@ export default function HistoryTable({ {t('history.planPrefix')} {set.planned.reps ?? '—'} {set.planned.loadKg != null - ? `/${set.planned.loadKg} kg` + ? `/${fmtLoadKg(set.planned.loadKg)} kg` : ''} {set.planned.restSec != null ? `/${set.planned.restSec} s` diff --git a/app/src/components/MessageAttachmentCard.tsx b/app/src/components/MessageAttachmentCard.tsx index c431612..dc55333 100644 --- a/app/src/components/MessageAttachmentCard.tsx +++ b/app/src/components/MessageAttachmentCard.tsx @@ -1,7 +1,7 @@ import { Dumbbell } from 'lucide-react'; import { useTranslation } from 'react-i18next'; import type { MessageAttachment } from '../api/types'; -import { fmtDate } from '../lib/format'; +import { fmtDate, fmtLoadKg } from '../lib/format'; import { localizedName } from '../lib/localizedName'; /** @@ -44,7 +44,9 @@ export default function MessageAttachmentCard({ {s.reps ?? '—'} {t('plans:exec.repsUnit')} RIR {s.rir ?? '—'} - {s.planned?.loadKg != null && {s.planned.loadKg} kg} + {s.planned?.loadKg != null && ( + {fmtLoadKg(s.planned.loadKg)} kg + )} ))} diff --git a/app/src/components/plans/PlanWeeks.tsx b/app/src/components/plans/PlanWeeks.tsx index 96c5990..914add7 100644 --- a/app/src/components/plans/PlanWeeks.tsx +++ b/app/src/components/plans/PlanWeeks.tsx @@ -5,7 +5,7 @@ import { Play } from 'lucide-react'; import { fmtDate } from '../../lib/format'; import { localizedName } from '../../lib/localizedName'; import { DAY_STATUS } from '../../lib/labels'; -import { dayName } from '../../lib/format'; +import { dayName, fmtLoadKg } from '../../lib/format'; import { Badge, Card, H2 } from '../ui'; import { buttonVariants } from '../ui/button'; import { cn } from '../../lib/utils'; @@ -74,7 +74,7 @@ export function PlanDayRow({ {ex.sets .map( (s) => - `${s.reps ?? '?'} ${i18n.t('plans:exec.repsUnit')}${s.loadKg ? ` @ ${s.loadKg}kg` : ''}`, + `${s.reps ?? '?'} ${i18n.t('plans:exec.repsUnit')}${s.loadKg ? ` @ ${fmtLoadKg(s.loadKg)}kg` : ''}`, ) .join(', ')} diff --git a/app/src/i18n/locales/en/plans.json b/app/src/i18n/locales/en/plans.json index 4d09df7..374717f 100644 --- a/app/src/i18n/locales/en/plans.json +++ b/app/src/i18n/locales/en/plans.json @@ -68,7 +68,8 @@ "resultsTitle": "Trainee results", "insertBtn": "Insert results", "lastSession": "Last session:", - "dayPickerAria": "Training days" + "dayPickerAria": "Training days", + "dayHistoryAria": "day with training history" }, "meta": { "title": "Title", @@ -152,7 +153,28 @@ "clearWeekLabel": "Clear", "removeDayTitle": "Remove day?", "removeDayDesc": "Remove {{day}} and its {{exercises}}?", - "removeDayLabel": "Remove day" + "removeDayLabel": "Remove day", + "historyBadge": "History", + "removeLockedTitle": "Remove a day with history?", + "removeLockedDesc": "{{day}} has training history (sessions or a settled status). The day will disappear from the plan, calendar and stats, but the training history will be kept. The change is recorded in the plan history along with your note.", + "removeLockedLabel": "Remove despite history", + "copyWeekLockedTitle": "Replace days that have history?", + "copyWeekLockedDesc": "This week contains days with training history. Replacing its days will remove them from the plan — the training history will be kept.", + "copyWeekLockedLabel": "Replace days", + "copyDayFrom": "Copy day from…", + "dayCopyTitle": "Copy {{day}} from…", + "dayCopyDesc": "Pick a day to copy from — the current day takes over its exercises and sets, and the week becomes standalone.", + "dayCopyLabel": "Copy: {{label}}", + "dayCopyLockedTitle": "Replace the day that has history?", + "dayCopyLockedDesc": "{{day}} has training history. Replacing it will remove the day from the plan — the training history will be kept.", + "dayCopyLockedLabel": "Replace day", + "shrinkWeeksLockedTitle": "Shorten the plan over weeks with history?", + "shrinkWeeksLockedDesc": "The weeks being removed contain days with training history. They will disappear from the plan and calendar — the training history will be kept.", + "shrinkWeeksLockedLabel": "Shorten plan", + "clearWeekHistoryNote": "This week contains {{count}} day(s) with training history. They will be removed from the plan — the training history will be kept.", + "clearWeekHistoryNote_one": "This week contains {{count}} day with training history. It will be removed from the plan — the training history will be kept.", + "clearWeekHistoryNote_other": "This week contains {{count}} days with training history. They will be removed from the plan — the training history will be kept.", + "historyGuardError": "Week {{week}}, {{day}} has training history — it was not removed. To remove it, use “Remove despite history”." }, "week": { "title": "Week {{n}}", diff --git a/app/src/i18n/locales/pl/plans.json b/app/src/i18n/locales/pl/plans.json index eebf4e7..5a537e1 100644 --- a/app/src/i18n/locales/pl/plans.json +++ b/app/src/i18n/locales/pl/plans.json @@ -68,7 +68,8 @@ "resultsTitle": "Wyniki podopiecznego", "insertBtn": "Wstaw wyniki", "lastSession": "Ostatnia sesja:", - "dayPickerAria": "Dni treningowe" + "dayPickerAria": "Dni treningowe", + "dayHistoryAria": "dzień z historią treningów" }, "meta": { "title": "Tytuł", @@ -152,7 +153,29 @@ "clearWeekLabel": "Wyczyść", "removeDayTitle": "Usunąć dzień?", "removeDayDesc": "Usunąć {{day}} i jego {{exercises}}?", - "removeDayLabel": "Usuń dzień" + "removeDayLabel": "Usuń dzień", + "historyBadge": "Historia", + "removeLockedTitle": "Usunąć dzień z historią?", + "removeLockedDesc": "{{day}} ma historię treningów (sesje lub rozliczony status). Dzień zniknie z planu, kalendarza i statystyk, ale historia treningowa zostanie zachowana. Zmiana trafi do historii planu razem z notatką.", + "removeLockedLabel": "Usuń mimo historii", + "copyWeekLockedTitle": "Podmienić dni z historią?", + "copyWeekLockedDesc": "Ten tydzień zawiera dni z historią treningów. Podmiana usunie je z planu — historia treningowa zostanie zachowana.", + "copyWeekLockedLabel": "Podmień dni", + "copyDayFrom": "Kopiuj dzień z…", + "dayCopyTitle": "Kopiuj {{day}} z…", + "dayCopyDesc": "Wybierz dzień do skopiowania — bieżący dzień przejmie jego ćwiczenia i serie, a tydzień stanie się samodzielny.", + "dayCopyLabel": "Kopiuj: {{label}}", + "dayCopyLockedTitle": "Podmienić dzień z historią?", + "dayCopyLockedDesc": "{{day}} ma historię treningów. Podmiana usunie ten dzień z planu — historia treningowa zostanie zachowana.", + "dayCopyLockedLabel": "Podmień dzień", + "shrinkWeeksLockedTitle": "Skrócić plan z tygodniami z historią?", + "shrinkWeeksLockedDesc": "Usuwane tygodnie zawierają dni z historią treningów. Znikną z planu i kalendarza — historia treningowa zostanie zachowana.", + "shrinkWeeksLockedLabel": "Skróć plan", + "clearWeekHistoryNote": "Ten tydzień zawiera {{count}} dni z historią treningów. Znikną z planu — historia treningowa zostanie zachowana.", + "clearWeekHistoryNote_one": "Ten tydzień zawiera {{count}} dzień z historią treningów. Zniknie z planu — historia treningowa zostanie zachowana.", + "clearWeekHistoryNote_few": "Ten tydzień zawiera {{count}} dni z historią treningów. Znikną z planu — historia treningowa zostanie zachowana.", + "clearWeekHistoryNote_many": "Ten tydzień zawiera {{count}} dni z historią treningów. Znikną z planu — historia treningowa zostanie zachowana.", + "historyGuardError": "Tydzień {{week}}, dzień {{day}} ma historię treningów — nie został usunięty. Aby go usunąć, użyj „Usuń mimo historii”." }, "week": { "title": "Tydzień {{n}}", diff --git a/app/src/lib/format.ts b/app/src/lib/format.ts index ce46f19..4a42dbb 100644 --- a/app/src/lib/format.ts +++ b/app/src/lib/format.ts @@ -113,6 +113,48 @@ export function fmtVolume(kg: number): string { return `${Math.round(kg).toLocaleString(currentTag())} kg`; } +/** Obciążenie w kg do wyświetlania: 62.5 → „62,5” (Intl, max 2 miejsca po przecinku). */ +export function fmtLoadKg(kg: number): string { + return kg.toLocaleString(currentTag(), { maximumFractionDigits: 2 }); +} + +/** + * Sanitizer wpisu obciążenia (stan edytora): cyfry + co najwyżej jeden separator + * przecinkowy z max 2 miejscami po przecinku; kropka normalizowana do przecinka, + * wartość ograniczona do limitu API (1000 kg). Zawsze zwraca string przechodzący + * LOAD_INPUT_RE albo ''. + */ +export function sanitizeLoadInput(raw: string): string { + let v = raw.replace(/[^\d.,]/g, '').replace(/\./g, ','); + const sep = v.indexOf(','); + if (sep !== -1) v = v.slice(0, sep + 1) + v.slice(sep + 1).replace(/,/g, ''); + const [rawInt = '', rawDec = ''] = v.split(','); + let int = rawInt.replace(/^0+(?=\d)/, ''); + let dec = rawDec; + if (Number(int) >= 1000) { + int = '1000'; + dec = ''; + } + dec = dec.slice(0, 2); + if (int === '' && dec === '') return ''; + if (int === '') int = '0'; + return dec === '' ? int : `${int},${dec}`; +} + +/** Dopuszczalna forma wpisu obciążenia: całkowita lub z przecinkiem (max 2 miejsca). */ +const LOAD_INPUT_RE = /^\d{1,4}(?:[.,]\d{1,2})?$/; + +/** + * Parsowanie wartości obciążenia po sanityzacji (separator ',' lub '.') do number; + * nieprawidłowa/pusta lub 0 (brak obciążenia) → null — nigdy NaN. + */ +export function parseLoadInput(v: string): number | null { + const s = v.trim(); + if (!LOAD_INPUT_RE.test(s)) return null; + const n = Number(s.replace(',', '.')); + return Number.isFinite(n) && n > 0 ? n : null; +} + /** Czas trwania sesji: „45 min”, „1 h 30 min”. */ export function fmtDuration(startIso: string, endIso: string): string { const min = Math.round((new Date(endIso).getTime() - new Date(startIso).getTime()) / 60000); diff --git a/app/src/pages/DayExecution.tsx b/app/src/pages/DayExecution.tsx index faec699..1cf364f 100644 --- a/app/src/pages/DayExecution.tsx +++ b/app/src/pages/DayExecution.tsx @@ -21,7 +21,7 @@ import { useSession, updateSessionSet, } from '../api/queries'; -import { fmtDate, dayName, setsPlural } from '../lib/format'; +import { fmtDate, fmtLoadKg, dayName, setsPlural } from '../lib/format'; import { localizedName } from '../lib/localizedName'; import { SESSION_STATUS, muscleName } from '../lib/labels'; import type { Exercise, PlanSet, Session, SessionExercise, SessionSet } from '../api/types'; @@ -231,7 +231,7 @@ function SetRow({ {planned.loadKg != null && ( <> - {planned.loadKg} kg + {fmtLoadKg(planned.loadKg)} kg )} {planned.loadKg != null && planned.reps != null ? ' × ' : ''} diff --git a/app/src/pages/plans/PlanEditor.tsx b/app/src/pages/plans/PlanEditor.tsx index 3e1b8fd..f329700 100644 --- a/app/src/pages/plans/PlanEditor.tsx +++ b/app/src/pages/plans/PlanEditor.tsx @@ -15,7 +15,8 @@ import { useExercises, type PlanBody, } from '../../api/queries'; -import { CalendarX, Check, ChevronLeft, ChevronRight, Unlink } from 'lucide-react'; +import { CalendarX, Check, ChevronLeft, ChevronRight, Copy, History, Unlink } from 'lucide-react'; +import { ApiError } from '../../api/client'; import { BackButton, Badge, @@ -24,6 +25,7 @@ import { EmptyState, H3, isPastWeek, + Modal, Skeleton, Tabs, type BadgeColor, @@ -32,7 +34,7 @@ import { useToast } from '../../components/toast'; import { cn } from '../../lib/utils'; import { localizedName } from '../../lib/localizedName'; import { exerciseAvailableAtGym } from '../../lib/equipment'; -import { dayName } from '../../lib/format'; +import { dayName, parseLoadInput } from '../../lib/format'; import { dayCountLabel, exerciseCountLabel } from '../../lib/labels'; import { useTopbar } from '../../topbar'; import { displayedDaysOf, type EditorDay, type EditorWeek } from './plan-editor/types'; @@ -172,6 +174,7 @@ export default function PlanEditor() { setStep(n); return; } + setDayCopyOpen(false); if (n === 2 && step1Valid) setStep(2); if (n === 3 && step1Valid) setStep(3); }; @@ -235,6 +238,18 @@ export default function PlanEditor() { const [confirmExit, setConfirmExit] = useState(false); const [clearWeekIdx, setClearWeekIdx] = useState(null); const [removeDayReq, setRemoveDayReq] = useState<{ wi: number; dow: number } | null>(null); + // Usunięcie dnia z historią (aktywny plan): osobne potwierdzenie + forceRemoveDays w payloadzie. + const [removeLockedReq, setRemoveLockedReq] = useState<{ wi: number; dow: number } | null>(null); + const [copyWeekReq, setCopyWeekReq] = useState<{ srcWi: number } | null>(null); + // „Kopiuj dzień z…”: wybór dnia-źródła (modal) + podmiana dnia z historią (potwierdzenie) + const [dayCopyOpen, setDayCopyOpen] = useState(false); + const [dayCopyReq, setDayCopyReq] = useState<{ + targetDow: number; + srcWi: number; + srcDow: number; + } | null>(null); + const [shrinkReq, setShrinkReq] = useState<{ n: number } | null>(null); + const [forceRemoveDays, setForceRemoveDays] = useState(false); const [titleTouched, setTitleTouched] = useState(false); // Notatka audytowa (edycja planu ACTIVE) — wymagana, gdy coś zmieniamy const [changeNote, setChangeNoteState] = useState(''); @@ -294,6 +309,11 @@ export default function PlanEditor() { return { text: dayCountLabel(days.length), color: 'green' }; }; + // Dni z historią treningową w wyświetlanej treści tygodnia: w aktywnym planie + // ich usunięcie to soft-remove (historia zostaje) — wymaga świadomego potwierdzenia. + const historyDaysOf = (wi: number) => + displayedDaysOf(editor.weeks, wi).filter((d) => d.hasHistory); + // Kropka statusu na zakładce tygodnia (kolory spójne z badge) const DOT_COLORS: Record = { green: 'bg-accent', @@ -354,7 +374,7 @@ export default function PlanEditor() { ...(keepIds && s.id ? { id: s.id } : {}), index: si, reps: s.reps ? parseInt(s.reps) : null, - loadKg: s.loadKg ? parseFloat(s.loadKg) : null, + loadKg: parseLoadInput(s.loadKg), restSec: s.restSec ? parseInt(s.restSec) : null, rir: s.rir !== '' ? parseInt(s.rir) : null, })), @@ -364,6 +384,9 @@ export default function PlanEditor() { }), }; if (noteRequired) body.changeNote = changeNote.trim(); + // Dzień z historią usunięty za potwierdzeniem „Usuń mimo historii” — backend + // soft-remuje go (removedAt), historia sesji/serii zostaje w bazie. + if (isPlanActive && forceRemoveDays) body.forceRemoveDays = true; // Data startu w obu trybach — przy tworzeniu: plan tworzony i aktywowany w jednym // kroku; przy edycji (DRAFT): zapis = aktualizacja struktury + aktywacja. // Tydzień startu: bieżący lub przyszły (WeekPicker blokuje minione; guard zapasowy). @@ -410,7 +433,22 @@ export default function PlanEditor() { } navigate(targetPath); } catch (err) { - push(err instanceof Error ? err.message : t('wizard.saveError'), 'error'); + if (err instanceof ApiError && err.code === 'PLAN_DAY_HAS_HISTORY') { + // Zapasowy guard (np. dzień z historią usunięty mimochodem): skocz do wskazanego dnia. + const d = (err.body?.error?.details ?? {}) as { weekIndex?: number; dayOfWeek?: number }; + push( + t('wizard.historyGuardError', { + week: (d.weekIndex ?? 0) + 1, + day: d.dayOfWeek != null ? dayName(d.dayOfWeek).toLowerCase() : '', + }), + 'error', + ); + setStep(2); + if (d.weekIndex != null) setActiveWeek(d.weekIndex); + if (d.dayOfWeek != null) setActiveDow(d.dayOfWeek); + } else { + push(err instanceof Error ? err.message : t('wizard.saveError'), 'error'); + } } finally { setSaving(false); } @@ -481,6 +519,36 @@ export default function PlanEditor() { }, ]; }); + // Źródła „Kopiuj dzień z…” — każdy dzień z ćwiczeniami poza edytowanym (ten tydzień: + // inne dni tygodnia; inne tygodnie: dowolny dzień, lustrzane źródła rozwiązane) + const dayCopySources = editor.weeks.flatMap((w, wi) => + displayedDaysOf(editor.weeks, wi) + .filter((d) => d.exercises.length > 0 && !(wi === activeWi && d.dayOfWeek === effDow)) + .map((d) => { + const alias = w.customName.trim(); + return { + wi, + dow: d.dayOfWeek, + label: + wi === activeWi + ? dayName(d.dayOfWeek) + : alias + ? `${alias} — ${dayName(d.dayOfWeek)}` + : `${t('week.title', { n: wi + 1 })} — ${dayName(d.dayOfWeek)}`, + summary: exerciseCountLabel(d.exercises.length), + }; + }), + ); + // Podmiana edytowanego dnia (aktywny plan) gdy ma historię — potwierdzenie + forceRemoveDays + const applyDayCopy = (srcWi: number, srcDow: number) => { + if (effDow == null) return; + const targetDay = weekDays.find((d) => d.dayOfWeek === effDow); + if (isPlanActive && targetDay?.hasHistory) { + setDayCopyReq({ targetDow: effDow, srcWi, srcDow }); + } else { + editor.copyDayTo(activeWi, effDow, srcWi, srcDow); + } + }; return ( <> @@ -496,7 +564,19 @@ export default function PlanEditor() { onTitleBlur={() => setTitleTouched(true)} titleError={titleError} weeksCount={editor.weeksCount} - onWeeksCountChange={editor.setWeeksCount} + onWeeksCountChange={(n) => { + // Skrócenie planu, który usunęłoby tygodnie z dniami z historią — + // potwierdzenie + forceRemoveDays (soft-remove, historia zostaje). + if ( + isPlanActive && + n < editor.weeks.length && + editor.weeks.slice(n).some((w) => w.days.some((d) => d.hasHistory)) + ) { + setShrinkReq({ n }); + } else { + editor.setWeeksCount(n); + } + }} gymOptions={gymOptions} gymId={editor.gymId} onGymIdChange={editor.setGymId} @@ -569,7 +649,15 @@ export default function PlanEditor() { customName={week.customName} onCustomNameChange={(v) => editor.setWeekAlias(activeWi, v)} copySources={copySources} - onCopyFrom={(srcWi) => editor.copyFromWeek(activeWi, srcWi)} + onCopyFrom={(srcWi) => { + // Podmiana dni tygodnia z historią (aktywny plan) — stare wiersze + // znikają z planu: potwierdzenie + forceRemoveDays. + if (isPlanActive && weekDays.some((d) => d.hasHistory)) { + setCopyWeekReq({ srcWi }); + } else { + editor.copyFromWeek(activeWi, srcWi); + } + }} canClear={weekDays.length > 0 || !week.detached} onClear={() => setClearWeekIdx(activeWi)} > @@ -608,6 +696,11 @@ export default function PlanEditor() { <> d.dayOfWeek)) + : undefined + } onAddDay={(dow) => { editor.addDay(activeWi, dow); // teraz, gdy dni są podzakładkami — wyląduj na nowo dodanym dniu @@ -615,9 +708,14 @@ export default function PlanEditor() { }} onRemoveDay={(dow) => { const day = weekDays.find((d) => d.dayOfWeek === dow); - // dzień z ćwiczeniami: potwierdzenie (tap na mobile nie może być destrukcyjny) - if (day && day.exercises.length > 0) setRemoveDayReq({ wi: activeWi, dow }); - else editor.removeDay(activeWi, dow); + if (!day) return; + // dzień z historią (aktywny plan): świadome potwierdzenie + forceRemoveDays + if (isPlanActive && day.hasHistory) { + setRemoveLockedReq({ wi: activeWi, dow }); + } else if (day.exercises.length > 0) { + // dzień z ćwiczeniami: potwierdzenie (tap na mobile nie może być destrukcyjny) + setRemoveDayReq({ wi: activeWi, dow }); + } else editor.removeDay(activeWi, dow); }} /> @@ -640,6 +738,19 @@ export default function PlanEditor() { przy ≥2 dniach, ruch zapętlony po dniach treningowych), licznik ćwiczeń zawsze przy prawej krawędzi */}
+ {/* Kopiowanie pojedynczego dnia (ten sam dzień tygodnia w innym + tygodniu lub inny dzień tygodnia) — wybór źródła w modalu */} + {dayCopySources.length > 0 && ( + + )} {/* Przy jednym dniu strzałek nie ma, ale ich miejsce zostaje — nazwa dnia zawsze w tym samym punkcie układu */}
@@ -671,6 +782,12 @@ export default function PlanEditor() {
+ {isPlanActive && activeDay.hasHistory && ( + + + {t('wizard.historyBadge')} + + )} 0 ? 'green' : 'gray'} @@ -719,6 +836,34 @@ export default function PlanEditor() { )} + + {dayCopyOpen && dayCopySources.length > 0 && effDow != null && ( + setDayCopyOpen(false)} + title={t('wizard.dayCopyTitle', { day: dayName(effDow) })} + handle + > +

{t('wizard.dayCopyDesc')}

+
+ {dayCopySources.map((s) => ( + + ))} +
+
+ )}
)} @@ -748,11 +893,18 @@ export default function PlanEditor() { open={clearWeekIdx !== null} onClose={() => setClearWeekIdx(null)} onConfirm={() => { - if (clearWeekIdx !== null) editor.clearWeek(clearWeekIdx); + if (clearWeekIdx !== null) { + if (isPlanActive && historyDaysOf(clearWeekIdx).length > 0) setForceRemoveDays(true); + editor.clearWeek(clearWeekIdx); + } setClearWeekIdx(null); }} title={t('wizard.clearWeekTitle', { n: (clearWeekIdx ?? 0) + 1 })} - description={t('wizard.clearWeekDesc')} + description={ + clearWeekIdx !== null && isPlanActive && historyDaysOf(clearWeekIdx).length > 0 + ? t('wizard.clearWeekHistoryNote', { count: historyDaysOf(clearWeekIdx).length }) + : t('wizard.clearWeekDesc') + } confirmLabel={t('wizard.clearWeekLabel')} danger /> @@ -780,6 +932,70 @@ export default function PlanEditor() { confirmLabel={t('wizard.removeDayLabel')} danger /> + setRemoveLockedReq(null)} + onConfirm={() => { + if (removeLockedReq) { + editor.removeDay(removeLockedReq.wi, removeLockedReq.dow); + setForceRemoveDays(true); + } + setRemoveLockedReq(null); + }} + title={t('wizard.removeLockedTitle')} + description={t('wizard.removeLockedDesc', { + day: removeLockedReq ? dayName(removeLockedReq.dow).toLowerCase() : '', + })} + confirmLabel={t('wizard.removeLockedLabel')} + danger + /> + setCopyWeekReq(null)} + onConfirm={() => { + if (copyWeekReq) { + editor.copyFromWeek(activeWi, copyWeekReq.srcWi); + setForceRemoveDays(true); + } + setCopyWeekReq(null); + }} + title={t('wizard.copyWeekLockedTitle')} + description={t('wizard.copyWeekLockedDesc')} + confirmLabel={t('wizard.copyWeekLockedLabel')} + danger + /> + setDayCopyReq(null)} + onConfirm={() => { + if (dayCopyReq) { + editor.copyDayTo(activeWi, dayCopyReq.targetDow, dayCopyReq.srcWi, dayCopyReq.srcDow); + setForceRemoveDays(true); + } + setDayCopyReq(null); + }} + title={t('wizard.dayCopyLockedTitle')} + description={t('wizard.dayCopyLockedDesc', { + day: dayCopyReq ? dayName(dayCopyReq.targetDow).toLowerCase() : '', + })} + confirmLabel={t('wizard.dayCopyLockedLabel')} + danger + /> + setShrinkReq(null)} + onConfirm={() => { + if (shrinkReq) { + editor.setWeeksCount(shrinkReq.n); + setForceRemoveDays(true); + } + setShrinkReq(null); + }} + title={t('wizard.shrinkWeeksLockedTitle')} + description={t('wizard.shrinkWeeksLockedDesc')} + confirmLabel={t('wizard.shrinkWeeksLockedLabel')} + danger + /> ); } diff --git a/app/src/pages/plans/plan-editor/DayPicker.tsx b/app/src/pages/plans/plan-editor/DayPicker.tsx index 91df1b4..c0494eb 100644 --- a/app/src/pages/plans/plan-editor/DayPicker.tsx +++ b/app/src/pages/plans/plan-editor/DayPicker.tsx @@ -1,16 +1,22 @@ import { useTranslation } from 'react-i18next'; +import { Lock } from 'lucide-react'; import { dayName } from '../../../lib/format'; import type { EditorDay } from './types'; /* Wybór dni treningowych tygodnia: siatka 7 dni (touch targety 44px, aria-label z pełną nazwą dnia). Pomarańczowy = dzień treningowy, kropka = dzień z ćwiczeniami. + Kłódka = dzień z historią treningową (w aktywnym planie: usunięcie wymaga + świadomej zgody, historia zostaje). Dzień edytowany przełącza stepper „« dzień »” (PlanEditor) — bez dublowania nazw. */ export function DayPicker({ days, + lockedDows, onAddDay, onRemoveDay, }: { days: EditorDay[]; + /** Dni z historią treningową — sygnalizowane kłódką. */ + lockedDows?: Set; onAddDay: (dow: number) => void; onRemoveDay: (dow: number) => void; }) { @@ -20,12 +26,13 @@ export function DayPicker({ {[1, 2, 3, 4, 5, 6, 7].map((dow) => { const day = days.find((d) => d.dayOfWeek === dow); const selected = !!day; + const locked = selected && !!lockedDows?.has(dow); return (