From b24f11d76b4c41634d5ecc2c00dab96b668f2a0e Mon Sep 17 00:00:00 2001 From: tisachi Date: Thu, 5 Nov 2026 23:58:38 +0100 Subject: [PATCH] App: krok 1 kreatora planu wg makiety - pola Tytul/Dlugosc/Silownia w jednym rzedzie z ikonami, kalendarz tygodni startu w osobnej karcie (wiersz = tydzien Pn-Nd, nawigacja < Dzis >), autofocus na tytule przy nowym planie (weekPicker.today w i18n; testy unit + e2e) --- app/src/components/ui.tsx | 4 +- app/src/components/ui/field.tsx | 15 +- app/src/components/ui/week-picker.tsx | 164 ++++++++++------- app/src/i18n/locales/en/common.json | 3 +- app/src/i18n/locales/en/plans.json | 3 +- app/src/i18n/locales/pl/common.json | 3 +- app/src/i18n/locales/pl/plans.json | 3 +- app/src/pages/plans/PlanEditor.tsx | 1 + .../pages/plans/plan-editor/PlanMetaForm.tsx | 174 ++++++++++-------- app/test/PlanEditor.test.tsx | 14 ++ 10 files changed, 236 insertions(+), 148 deletions(-) diff --git a/app/src/components/ui.tsx b/app/src/components/ui.tsx index 509dd96..f80b78c 100644 --- a/app/src/components/ui.tsx +++ b/app/src/components/ui.tsx @@ -122,15 +122,17 @@ export function Label({ children, className }: { children: ReactNode; className? export function Field({ label, + labelIcon, children, className, }: { label: string; + labelIcon?: ReactNode; children: ReactNode; className?: string; }) { return ( - + {children} ); diff --git a/app/src/components/ui/field.tsx b/app/src/components/ui/field.tsx index 8801ce4..593c261 100644 --- a/app/src/components/ui/field.tsx +++ b/app/src/components/ui/field.tsx @@ -4,12 +4,23 @@ import { cn } from '../../lib/utils'; interface FieldProps extends React.HTMLAttributes { label: string; + /** Ikona przed etykietą (np. Tag/Calendar w formularzu planu); dekoracyjna. */ + labelIcon?: React.ReactNode; } -function Field({ className, label, children, ...props }: FieldProps) { +function Field({ className, label, labelIcon, children, ...props }: FieldProps) { return (
- + {children}
); diff --git a/app/src/components/ui/week-picker.tsx b/app/src/components/ui/week-picker.tsx index e30b1fa..0959504 100644 --- a/app/src/components/ui/week-picker.tsx +++ b/app/src/components/ui/week-picker.tsx @@ -1,7 +1,6 @@ import { useState } from 'react'; import { useTranslation } from 'react-i18next'; -import { ChevronLeft, ChevronRight } from 'lucide-react'; -import { Button } from './button'; +import { CalendarDays, ChevronLeft, ChevronRight } from 'lucide-react'; import { formatMonth } from '../../lib/format'; import { fmtDate } from '../../lib/format'; import { cn } from '../../lib/utils'; @@ -42,9 +41,15 @@ export function isPastWeek(monday: string): boolean { return new Date(y, m - 1, d) < currentMonday(); } -/* Wybór tygodnia startu: siatka miesiąca, w której kliknięcie dowolnego dnia zaznacza - CAŁY tydzień (Pn–Nd) — data startu to poniedziałek zaznaczonego tygodnia. - Minione tygodnie są zablokowane (start nie może być w przeszłości). */ +/* Kwadratowy target nawigacji — ta sama estetyka co pola formularza (bg-input + + hover w akcencie). */ +const NAV_BTN = + 'grid h-10 min-w-10 cursor-pointer place-items-center rounded-[10px] border border-line bg-input text-dim transition-all duration-150 hover:border-accent hover:text-accent-text active:scale-95 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/60'; + +/* Wybór tygodnia startu: kalendarz miesiąca, w którym każdy tydzień (Pn–Nd) jest + osobnym wierszem — kliknięcie dowolnego dnia zaznacza CAŁY tydzień (tło w akcencie), + a data startu to poniedziałek zaznaczonego tygodnia. Minione tygodnie są zablokowane + (start nie może być w przeszłości). Nawigacja miesiącami + skrót „Dziś”. */ export function WeekPicker({ value, onChange, @@ -71,80 +76,115 @@ export function WeekPicker({ const d = new Date(y, m - 1 + delta, 1); setView([d.getFullYear(), d.getMonth() + 1]); }; + const goToday = () => setView([now.getFullYear(), now.getMonth() + 1]); - // Monday-first grid + // Monday-first grid: 6 pełnych wierszy tygodni (42 dni) — każdy wiersz to + // jednostka wyboru (cały tydzień). const firstDay = new Date(y, m - 1, 1); const startOffset = (firstDay.getDay() + 6) % 7; const gridStart = new Date(y, m - 1, 1 - startOffset); - const cells: Date[] = []; - for (let i = 0; i < 42; i++) { - const d = new Date(gridStart); - d.setDate(gridStart.getDate() + i); - cells.push(d); + const rows: Date[][] = []; + for (let wi = 0; wi < 6; wi++) { + const row: Date[] = []; + for (let i = 0; i < 7; i++) { + const d = new Date(gridStart); + d.setDate(gridStart.getDate() + wi * 7 + i); + row.push(d); + } + rows.push(row); } const selMondayKey = value ? localDayKey(mondayOf(parseIsoLocal(value))) : null; + const todayKey = localDayKey(now); return (
-
- - - {formatMonth(`${y}-${String(m).padStart(2, '0')}`)} - - +
+
+
+
+ + + +
-
- {dows.map((d) => ( -
- {d} -
- ))} - {cells.map((d, i) => { - const inMonth = d.getMonth() === m - 1; - const weekMonday = mondayOf(d); - const isPast = isPastWeek(localDayKey(weekMonday)); - const isSel = selMondayKey != null && localDayKey(weekMonday) === selMondayKey; +
+
+ {dows.map((d) => ( +
+ {d} +
+ ))} +
+ {rows.map((row) => { + const weekMonday = row[0]; + const weekKey = localDayKey(weekMonday); + const past = isPastWeek(weekKey); + const sel = selMondayKey === weekKey; return ( - + {row.map((d, i) => { + const inMonth = d.getMonth() === m - 1; + const isToday = localDayKey(d) === todayKey; + return ( + + ); + })} +
); })}
{value && ( -

+

{t('weekPicker.startWeek', { from: fmtDate(value), to: fmtDate(localDayKey(addDaysLocal(parseIsoLocal(value), 6))), diff --git a/app/src/i18n/locales/en/common.json b/app/src/i18n/locales/en/common.json index b65f587..6076deb 100644 --- a/app/src/i18n/locales/en/common.json +++ b/app/src/i18n/locales/en/common.json @@ -57,7 +57,8 @@ "weekPicker": { "dows": ["Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"], "groupAria": "Start week selection", - "startWeek": "Start: week {{from}} – {{to}}" + "startWeek": "Start: week {{from}} – {{to}}", + "today": "Today" }, "weekShort": ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"], "fmt": { diff --git a/app/src/i18n/locales/en/plans.json b/app/src/i18n/locales/en/plans.json index 8be5fac..092e839 100644 --- a/app/src/i18n/locales/en/plans.json +++ b/app/src/i18n/locales/en/plans.json @@ -85,8 +85,7 @@ "length": "Length (weeks)", "gym": "Gym", "noGym": "No gym", - "gymHint": "Limits the exercise list to available equipment.", - "activateHint": "Optionally pick a start week — the plan is activated right away (start = Monday of the picked week) and training day dates are calculated automatically. Without a week the plan stays a draft.", + "activateHint": "Optionally mark the start week — the plan is activated right away (start = Monday of the marked week).", "startDateLockedHint": "This plan is in progress — its start date cannot change.", "changeNoteLabel": "Change note", "changeNotePlaceholder": "What you change in the in-progress plan and why", diff --git a/app/src/i18n/locales/pl/common.json b/app/src/i18n/locales/pl/common.json index 7531d5b..a557aa4 100644 --- a/app/src/i18n/locales/pl/common.json +++ b/app/src/i18n/locales/pl/common.json @@ -57,7 +57,8 @@ "weekPicker": { "dows": ["Pn", "Wt", "Śr", "Cz", "Pt", "So", "Nd"], "groupAria": "Wybór tygodnia startu", - "startWeek": "Start: tydzień {{from}} – {{to}}" + "startWeek": "Start: tydzień {{from}} – {{to}}", + "today": "Dziś" }, "weekShort": ["Pon", "Wt", "Śr", "Czw", "Pt", "Sob", "Niedz"], "fmt": { diff --git a/app/src/i18n/locales/pl/plans.json b/app/src/i18n/locales/pl/plans.json index 8f107f5..80552bd 100644 --- a/app/src/i18n/locales/pl/plans.json +++ b/app/src/i18n/locales/pl/plans.json @@ -85,8 +85,7 @@ "length": "Długość (tygodnie)", "gym": "Siłownia", "noGym": "Bez siłowni", - "gymHint": "Ogranicza listę ćwiczeń do dostępnego sprzętu.", - "activateHint": "Opcjonalnie zaznacz tydzień startu — plan zostanie od razu aktywowany (start = poniedziałek zaznaczonego tygodnia), a daty dni treningowych wyliczone automatycznie. Bez tygodnia plan pozostanie szkicem.", + "activateHint": "Opcjonalnie zaznacz tydzień startu — plan zostanie od razu aktywowany (start = poniedziałek zaznaczonego tygodnia).", "startDateLockedHint": "Plan jest realizowany — data startu jest niezmienna.", "changeNoteLabel": "Notatka o zmianach", "changeNotePlaceholder": "Co i dlaczego zmieniasz w realizowanym planie", diff --git a/app/src/pages/plans/PlanEditor.tsx b/app/src/pages/plans/PlanEditor.tsx index 652e8a3..e87f90d 100644 --- a/app/src/pages/plans/PlanEditor.tsx +++ b/app/src/pages/plans/PlanEditor.tsx @@ -572,6 +572,7 @@ export default function PlanEditor() { onTitleChange={editor.setTitle} onTitleBlur={() => setTitleTouched(true)} titleError={titleError} + autoFocusTitle={!isEdit} weeksCount={editor.weeksCount} onWeeksCountChange={(n) => { // Skrócenie planu, który usunęłoby tygodnie z dniami z historią — diff --git a/app/src/pages/plans/plan-editor/PlanMetaForm.tsx b/app/src/pages/plans/plan-editor/PlanMetaForm.tsx index 24adacf..af01506 100644 --- a/app/src/pages/plans/plan-editor/PlanMetaForm.tsx +++ b/app/src/pages/plans/plan-editor/PlanMetaForm.tsx @@ -1,18 +1,20 @@ import type { ReactNode } from 'react'; import { useTranslation } from 'react-i18next'; +import { CalendarDays, CircleSlash, Info, Tag } from 'lucide-react'; import { Card, ErrorText, Field, Input, Select, WeekPicker } from '../../../components/ui'; import { fmtDate } from '../../../lib/format'; -/* Meta planu: tytuł, długość, siłownia, tydzień startu (+ hint) — inputy w rzędzie, - kalendarz na pełną szerokość karty, błędy inline. Siłownia jest tu, bo realnie - decyduje o dostępnym sprzęcie w pickerze ćwiczeń (krok 2). - Plan w trakcie realizacji: start jest niezmienny (pole tylko do odczytu) i pojawia - się opcjonalna notatka o zmianach (historia edycji planu). */ +/* Meta planu (krok 1): karta pól — tytuł, długość, siłownia w jednym rzędzie + (ikony w etykietach) — oraz osobna karta kalendarza tygodnia startu. Siłownia + jest w kroku 1, bo realnie decyduje o dostępnym sprzęcie w pickerze ćwiczeń (krok 2). + Plan w trakcie realizacji: start jest niezmienny (pole tylko do odczytu zamiast + kalendarza) i pojawia się opcjonalna notatka o zmianach (historia edycji planu). */ export function PlanMetaForm({ title, onTitleChange, onTitleBlur, titleError, + autoFocusTitle = false, weeksCount, onWeeksCountChange, gymOptions, @@ -30,6 +32,8 @@ export function PlanMetaForm({ onTitleChange: (v: string) => void; onTitleBlur?: () => void; titleError?: string; + /** Nowy plan: fokus na tytule od razu po wejściu do kreatora. */ + autoFocusTitle?: boolean; weeksCount: number; onWeeksCountChange: (n: number) => void; /** Siłownie właściciela planu (członkostwa); pusta = komunikat `noGymNotice`. */ @@ -48,40 +52,47 @@ export function PlanMetaForm({ onSetChangeNote?: (v: string) => void; }) { const { t } = useTranslation('plans'); - const titleField = ( - - onTitleChange(e.target.value)} - onBlur={onTitleBlur} - placeholder={t('meta.titlePlaceholder')} - aria-invalid={titleError ? true : undefined} - /> - {titleError && {titleError}} - - ); - const weeksField = ( - - - - ); - return ( - -

- {titleField} - {weeksField} -
-
- - {gymOptions.length > 0 ? ( - <> + <> + +
+ } + className="mb-0" + > + onTitleChange(e.target.value)} + onBlur={onTitleBlur} + autoFocus={autoFocusTitle} + placeholder={t('meta.titlePlaceholder')} + aria-invalid={titleError ? true : undefined} + /> + {titleError && {titleError}} + + } + className="mb-0" + > + + + } + className="mb-0" + > + {gymOptions.length > 0 ? ( -

{t('meta.gymHint')}

- - ) : ( -

{noGymNotice}

- )} -
-
-
- - {startDateLocked ? ( - <> + ) : ( +

{noGymNotice}

+ )} +
+
+ {onSetChangeNote && ( +
+ +