From ad8d0b5e1767f6868eb8f466a5317510d28dcd10 Mon Sep 17 00:00:00 2001 From: tisachi Date: Sat, 17 Oct 2026 05:14:51 +0200 Subject: [PATCH] Dashboard: kafelek Ukonczone plany z liczba zrobionych treningow na dolnym prawym rogu --- app/src/lib/format.ts | 9 +++++++++ app/src/pages/Dashboard.tsx | 24 ++++++++++++++++++------ app/test/dashboard-stats.test.tsx | 3 +++ app/test/helpers.test.ts | 12 +++++++++++- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/app/src/lib/format.ts b/app/src/lib/format.ts index 7c94612..24809f3 100644 --- a/app/src/lib/format.ts +++ b/app/src/lib/format.ts @@ -54,6 +54,15 @@ export function daysPlural(n: number): string { return n === 1 ? '1 dzień' : `${n} dni`; } +/** Odmiana etykiety przy liczbie treningów: 1 → „zrobiony trening”, 3 → „zrobione treningi”, 5 → „zrobionych treningów”. */ +export function trainingsDonePlural(n: number): string { + if (n === 1) return 'zrobiony trening'; + const last = n % 10; + const lastTwo = n % 100; + if (last >= 2 && last <= 4 && !(lastTwo >= 12 && lastTwo <= 14)) return 'zrobione treningi'; + return 'zrobionych treningów'; +} + /** Dni kalendarzowe od danego dnia włącznie (tego samego dnia = 1). */ export function daysSince(iso: string): number { const s = new Date(iso); diff --git a/app/src/pages/Dashboard.tsx b/app/src/pages/Dashboard.tsx index bb7c5d6..e77813f 100644 --- a/app/src/pages/Dashboard.tsx +++ b/app/src/pages/Dashboard.tsx @@ -5,7 +5,7 @@ import type { LucideIcon } from 'lucide-react'; import { useActiveSession, useDashboard, useFeed } from '../api/queries'; import { FeedItemRow } from '../components/FeedItemRow'; import { useAuth } from '../store/auth'; -import { fmtDate, todayStr, daysPlural } from '../lib/format'; +import { fmtDate, todayStr, daysPlural, trainingsDonePlural } from '../lib/format'; import { DAY_NAMES, MUSCLE_NAMES } from '../lib/labels'; import { useTopbar } from '../topbar'; import { Button, Card, EmptyState, ErrorText, SectionHeader, Skeleton } from '../components/ui'; @@ -458,11 +458,23 @@ export default function Dashboard() { } /> - + {/* Plany + dorobek treningów (liczba na dole po prawej, jak w projekcie). */} + +
+ Ukończone plany +
+
+ {history.completedPlans} +
+
+
+ {history.sessions} +
+
+ {trainingsDonePlural(history.sessions)} +
+
+
)} diff --git a/app/test/dashboard-stats.test.tsx b/app/test/dashboard-stats.test.tsx index 7580d0d..7e8e4b1 100644 --- a/app/test/dashboard-stats.test.tsx +++ b/app/test/dashboard-stats.test.tsx @@ -157,6 +157,9 @@ describe('Dashboard — statystyki motywacyjne', () => { expect(await screen.findByText('rekord: 5 dni')).toBeInTheDocument(); expect(screen.getByText('Ukończone plany', { exact: true })).toBeInTheDocument(); + // Dorobek treningów w kafelku „Ukończone plany" (12 sesji z mocka → dop. „treningów"). + expect(screen.getByText('12', { exact: true })).toBeInTheDocument(); + expect(screen.getByText('zrobionych treningów', { exact: true })).toBeInTheDocument(); expect(screen.queryByText('ostatni: wczoraj')).not.toBeInTheDocument(); expect(screen.queryByText('Treningi', { exact: true })).not.toBeInTheDocument(); expect(screen.queryByText('Trenujesz od', { exact: true })).not.toBeInTheDocument(); diff --git a/app/test/helpers.test.ts b/app/test/helpers.test.ts index ae5a693..ec6138d 100644 --- a/app/test/helpers.test.ts +++ b/app/test/helpers.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect } from 'vitest'; -import { fmtDate, fmtDateTime, todayStr, monthStr, setsPlural } from '../src/lib/format'; +import { fmtDate, fmtDateTime, todayStr, monthStr, setsPlural, trainingsDonePlural } from '../src/lib/format'; import { MUSCLE_NAMES, DAY_NAMES, PLAN_STATUS, DAY_STATUS, SESSION_STATUS } from '../src/lib/labels'; describe('helpers', () => { @@ -65,4 +65,14 @@ describe('helpers', () => { expect(setsPlural(12)).toBe('zostało 12 serii'); expect(setsPlural(24)).toBe('zostały 24 serie'); }); + + it('trainingsDonePlural stosuje polską odmianę (etykieta bez liczby)', () => { + expect(trainingsDonePlural(1)).toBe('zrobiony trening'); + expect(trainingsDonePlural(2)).toBe('zrobione treningi'); + expect(trainingsDonePlural(4)).toBe('zrobione treningi'); + expect(trainingsDonePlural(5)).toBe('zrobionych treningów'); + expect(trainingsDonePlural(12)).toBe('zrobionych treningów'); + expect(trainingsDonePlural(22)).toBe('zrobione treningi'); + expect(trainingsDonePlural(25)).toBe('zrobionych treningów'); + }); });