Dashboard: kafelek Ukonczone plany z liczba zrobionych treningow na dolnym prawym rogu

This commit is contained in:
tisachi
2026-10-17 05:14:51 +02:00
parent 7483d5017e
commit ad8d0b5e17
4 changed files with 41 additions and 7 deletions

View File

@@ -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);

View File

@@ -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() {
</>
}
/>
<StatCard
className="sm:col-span-1"
label="Ukończone plany"
value={history.completedPlans}
/>
{/* Plany + dorobek treningów (liczba na dole po prawej, jak w projekcie). */}
<Card className="mb-0 flex min-w-0 flex-col items-start gap-0.5 p-5 sm:col-span-1">
<div className="text-[11px] font-bold uppercase tracking-[0.1em] text-dim">
Ukończone plany
</div>
<div className="font-display text-[1.9rem] font-bold leading-tight tracking-[-0.02em] tabular-nums">
{history.completedPlans}
</div>
<div className="mt-auto self-end text-right">
<div className="font-display text-[1.4rem] font-bold leading-tight tracking-[-0.02em] tabular-nums">
{history.sessions}
</div>
<div className="text-[11px] font-bold uppercase tracking-[0.1em] text-dim">
{trainingsDonePlural(history.sessions)}
</div>
</div>
</Card>
</div>
</>
)}

View File

@@ -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();

View File

@@ -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');
});
});