From 0c688c12c17d2d91af33b8ffaf6c0f75ba6964f1 Mon Sep 17 00:00:00 2001 From: tisachi Date: Sat, 17 Oct 2026 07:18:38 +0200 Subject: [PATCH] Profil: strony mierzone jako dwa niezalezne divy s wlasnymi danymi --- .../pages/profile/ProfileBodyParameters.tsx | 215 ++++++++++-------- app/test/ProfileBodyParameters.test.tsx | 23 +- app/test/ProfileCircumferences.test.tsx | 5 +- 3 files changed, 134 insertions(+), 109 deletions(-) diff --git a/app/src/pages/profile/ProfileBodyParameters.tsx b/app/src/pages/profile/ProfileBodyParameters.tsx index 415c01a..166dd3b 100644 --- a/app/src/pages/profile/ProfileBodyParameters.tsx +++ b/app/src/pages/profile/ProfileBodyParameters.tsx @@ -35,6 +35,7 @@ import { H3, Input, Modal, + PageHeader, Select, Skeleton, Tabs, @@ -155,18 +156,6 @@ function progressOf(g: PartGroup): { text: string; className: string } | null { return { text: `${signed(d)} ${g.unit} od pierwszego`, className }; } -/* Zmiana ostatniego pomiaru każdej strony vs poprzednik jej strony; 0 = bez zmian. */ -function sideDeltas(g: PartGroup): { side: Side; text: string; zero: boolean }[] { - return g.sidesPresent - .map((side) => { - const pts = g.points.filter((p) => p.side === side); - if (pts.length < 2) return null; - const d = pts[pts.length - 1].value - pts[pts.length - 2].value; - return { side, text: `${signed(d)} ${g.unit}`, zero: d === 0 }; - }) - .filter((x): x is { side: Side; text: string; zero: boolean } => x != null); -} - /* Osobny div postępu wybranej części: kierunek zmiany + wynik (strony osobno, gdy łączone). */ function ProgressCard({ down, @@ -298,7 +287,8 @@ function PartAreaChart({ ); } -/* Panel wybranej części: nagłówek (nazwa + ostatni pomiar) + wykres pełnej historii + lista pomiarów. */ +/* Panel wybranej części. Strony mierzone (lewy/prawy) = dwa niezależne divy, + każdy z własnym nagłówkiem, postępem, wykresem i listą — lewy zawsze pierwszy. */ function MeasurementPanel({ group, icon: Icon, @@ -312,71 +302,118 @@ function MeasurementPanel({ onShowMore: () => void; onDelete: (target: { kind: 'weight' | 'circumference'; id: string; label: string }) => void; }) { - const latest = group.points[group.points.length - 1]; const sided = group.sidesPresent.length > 1; + if (!sided) { + return ( + + + + ); + } + const labels = sideLabelsFor(group.part); + const unsidePoints = group.points.filter((p) => p.side == null); + return ( +
+ {(['left', 'right'] as Side[]) + .filter((s) => group.sidesPresent.includes(s)) + .map((s) => ( + + p.side === s)} + stroke={SIDE_STROKE[s]} + chartName={labels[s].toLowerCase()} + visible={visible} + onShowMore={onShowMore} + onDelete={onDelete} + /> + + ))} + {unsidePoints.length > 0 && ( + + + + )} +
+ ); +} + +/* Sekcja części/strony: nagłówek (nazwa + ostatni pomiar) + postęp + wykres historii + lista pomiarów. */ +function PartSection({ + title, + icon: Icon, + unit, + points, + stroke, + chartName, + visible, + onShowMore, + onDelete, +}: { + title: string; + icon: LucideIcon; + unit: 'kg' | 'cm'; + points: GroupPoint[]; + stroke: string; + chartName: string; + visible: number; + onShowMore: () => void; + onDelete: (target: { kind: 'weight' | 'circumference'; id: string; label: string }) => void; +}) { + const latest = points[points.length - 1]; // historia przekracza rok → oś X z rokiem (również przy przerwie >12 mies. w jednym roku) const withYear = - new Date(group.points[group.points.length - 1].date).getTime() - - new Date(group.points[0].date).getTime() > + new Date(points[points.length - 1].date).getTime() - new Date(points[0].date).getTime() > 300 * 86_400_000; - // strony osobno (lewa zawsze pierwsza) — dwa niezależne wykresy jeden pod drugim - const seriesList: { - key: string; - caption: string; - name: string; - stroke: string; - points: GroupPoint[]; - }[] = sided - ? (['left', 'right'] as Side[]) - .filter((s) => group.sidesPresent.includes(s)) - .map((s) => ({ - key: s, - caption: sideLabelsFor(group.part)[s], - name: sideLabelsFor(group.part)[s].toLowerCase(), - stroke: SIDE_STROKE[s], - points: group.points.filter((p) => p.side === s), - })) - : [ - { - key: 'all', - caption: '', - name: group.part, - stroke: unitStroke(group.unit), - points: group.points, - }, - ]; - // osobna strona: przy >1 strony wynik per strona, poza tym zmiana od pierwszego pomiaru - const deltas = sideDeltas(group); - const prog = progressOf(group); - const parts = - sided && deltas.length > 0 - ? deltas.map((d) => `${SIDE_LABELS[d.side]} ${d.zero ? 'bez zmian' : d.text}`).join(' · ') - : (prog?.text ?? ''); - const primary = parts || 'bez zmian'; + // postęp sekcji (dla strony: osobna, przy łączonej: per strona): zmiana od pierwszego pomiaru + const prog = progressOf({ part: title, unit, points, sidesPresent: [] }); + const primary = prog?.text ?? 'bez zmian'; const primaryClass = prog?.className ?? 'text-dim'; const sub = - group.points.length < 2 + points.length < 2 ? 'drugi pomiar pokaże zmianę' - : `${pomN(group.points.length)} · pierwszy → ostatni`; + : `${pomN(points.length)} · pierwszy → ostatni`; return ( - + <>
- + -

{group.part}

+

{title}

- {latest.value} {group.unit} - - - {latest.side ? `${SIDE_LABELS[latest.side]} · ` : ''} - {fmtDate(latest.date)} + {latest.value} {unit} + {fmtDate(latest.date)}
@@ -388,40 +425,27 @@ function MeasurementPanel({ sub={sub} /> - {seriesList.map((s, i) => ( -
0 ? 'mt-5' : undefined}> - {sided && ( -
- - {s.caption} -
- )} - {s.points.length >= 2 ? ( - - ) : ( -

Za mało danych na wykres (min. 2 pomiary).

- )} -
- ))} + {points.length >= 2 ? ( + + ) : ( +

Za mało danych na wykres (min. 2 pomiary).

+ )} {/* lista: najnowsze 3 + „Pokaż więcej" (kolejne 3); pełna historia w wykresie */}
    - {[...group.points] + {[...points] .reverse() .slice(0, visible) .map((p) => { - const kind = group.unit === 'kg' ? ('weight' as const) : ('circumference' as const); + const kind = unit === 'kg' ? ('weight' as const) : ('circumference' as const); const sideLabel = p.side ? ` · ${SIDE_LABELS[p.side]}` : ''; return (
  • - {p.value} {group.unit} + {p.value} {unit}
    {fmtDate(p.date)} @@ -445,7 +469,7 @@ function MeasurementPanel({ onDelete({ kind, id: p.id, - label: `${p.name} ${p.value} ${group.unit} (${fmtDate(p.date)})`, + label: `${p.name} ${p.value} ${unit} (${fmtDate(p.date)})`, }) } className="p-1.5 -m-1.5 text-dim hover:text-danger cursor-pointer shrink-0" @@ -457,13 +481,13 @@ function MeasurementPanel({ ); })}
- {group.points.length > visible && ( + {points.length > visible && ( )}
-
+ ); } @@ -626,7 +650,8 @@ export default function ProfileBodyParameters() { // menu top: jedyna akcja strony (tworzenie pomiaru) — treść = dane i wybór części useTopbar({ - title: 'Parametry ciała', + // topbar = rodzic („Profil”), nazwa podstrony w PageHeader poniżej (h2) + title: 'Profil', back: '/profile', actions: [{ label: 'Dodaj pomiar', onClick: () => setAddOpen(true), icon: Plus }], }); @@ -752,10 +777,8 @@ export default function ProfileBodyParameters() { return ( <> - {/* podstrona: „Wstecz” do przeglądu profilu (na telefonie = „<” w topmenu) */} -
- -
+ {/* podstrona: h2 z nazwą sekcji + „Wstecz” (na telefonie additionally „<” w topmenu) */} + } /> {active == null ? ( { renderApp(); await loginToProfile(user); - // pasek kaflów: `Bicepcs` scalony z grupą Biceps — nie ma osobnego kafla + // pasek zakładek: `Bicepcs` scalony z grupą Biceps — nie ma osobnej zakładki await user.click(selectPart('Biceps')); expect(screen.queryByText('Bicepcs')).not.toBeInTheDocument(); - // nagłówek panelu: najnowszy pomiar grupy (40 cm, 20.08) + // niezależne divy stron + zbiorczy dla pomiarów bez strony + expect(screen.getByRole('heading', { name: 'Biceps — lewy', level: 3 })).toBeInTheDocument(); + expect(screen.getByRole('heading', { name: 'Biceps — prawy', level: 3 })).toBeInTheDocument(); + // nagłówek sekcji zbiorczej: najnowszy pomiar bez strony (40 cm, 20.08) expect(screen.getAllByText('40 cm').length).toBe(2); // nagłówek + wiersz listy - // legenda obu stron przy wykresie - expect(screen.getByText('Lewy')).toBeInTheDocument(); - expect(screen.getByText('Prawy')).toBeInTheDocument(); // wiersze listy z oznaczeniem strony expect(screen.getByText('15.08.2026 · Lewy')).toBeInTheDocument(); expect(screen.getByText('15.08.2026 · Prawy')).toBeInTheDocument(); @@ -236,11 +237,11 @@ describe('Profile — body parameter removal', () => { await loginToProfile(user); await user.click(selectPart('Udo')); - // nagłówek panelu (ostatni 56) + wiersz listy + // nagłówek sekcji strony (ostatni 56) + wiersz listy expect((await screen.findAllByText('56 cm')).length).toBeGreaterThanOrEqual(2); - // dwa podpisyane wykresy: lewy zawsze przed prawym - const lewy = screen.getByText('Lewe'); - const prawy = screen.getByText('Prawe'); + // dwa niezależne divy: „Udo — lewe” zawsze przed „Udo — prawe” + const lewy = screen.getByRole('heading', { name: 'Udo — lewe', level: 3 }); + const prawy = screen.getByRole('heading', { name: 'Udo — prawe', level: 3 }); expect(lewy.compareDocumentPosition(prawy) & Node.DOCUMENT_POSITION_FOLLOWING).toBeTruthy(); // strona z jednym pomiarem uczciwie sygnalizuje za mało danych expect(screen.getByText(/Za mało danych na wykres/)).toBeInTheDocument(); diff --git a/app/test/ProfileCircumferences.test.tsx b/app/test/ProfileCircumferences.test.tsx index 79dfe14..9a7a339 100644 --- a/app/test/ProfileCircumferences.test.tsx +++ b/app/test/ProfileCircumferences.test.tsx @@ -86,9 +86,10 @@ async function loginToProfile(user: userEvent.User) { expect(await screen.findByRole('heading', { name: 'Profil' })).toBeInTheDocument(); // body parameters live on their own subpage — open it via the tile await user.click(await screen.findByRole('link', { name: /Parametry ciała/ })); - // wspólna nazwa sekcji: topbar (h1) = PageHeader (h2) + // topbar (h1) = rodzic „Profil”, nazwa podstrony niżej jako PageHeader (h2) + expect(await screen.findByRole('heading', { name: 'Profil', level: 1 })).toBeInTheDocument(); expect( - await screen.findByRole('heading', { name: 'Parametry ciała', level: 1 }), + await screen.findByRole('heading', { name: 'Parametry ciała', level: 2 }), ).toBeInTheDocument(); }