Dashboard: Historia w jednej linii - Serie+Killstreak 4/5, Ukończone plany 1/5 (usuniete Treningi i Trenujesz od)
This commit is contained in:
@@ -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, timeAgo, todayStr, daysPlural, daysSince } from '../lib/format';
|
||||
import { fmtDate, todayStr, daysPlural } 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';
|
||||
@@ -111,9 +111,19 @@ function ProgressRing({ percent }: { percent: number }) {
|
||||
}
|
||||
|
||||
/* Karta statystyki: lbl + duża liczba (Space Grotesk) + opcjonalny dopisek kontekstowy. */
|
||||
function StatCard({ label, value, sub }: { label: string; value: ReactNode; sub?: ReactNode }) {
|
||||
function StatCard({
|
||||
label,
|
||||
value,
|
||||
sub,
|
||||
className = '',
|
||||
}: {
|
||||
label: string;
|
||||
value: ReactNode;
|
||||
sub?: ReactNode;
|
||||
className?: string;
|
||||
}) {
|
||||
return (
|
||||
<Card className="mb-0 flex min-w-0 flex-col items-start gap-0.5 p-5">
|
||||
<Card className={`mb-0 flex min-w-0 flex-col items-start gap-0.5 p-5 ${className}`.trim()}>
|
||||
<div className="text-[11px] font-bold uppercase tracking-[0.1em] text-dim">{label}</div>
|
||||
<div className="flex items-center gap-1.5 font-display text-[1.9rem] font-bold leading-tight tracking-[-0.02em] tabular-nums">
|
||||
{value}
|
||||
@@ -318,8 +328,6 @@ export default function Dashboard() {
|
||||
// Fallbacki dla starszych/okrojonych odpowiedzi (np. mocki testów jednostkowych).
|
||||
const week = data.week ?? null;
|
||||
const killstreakBest = data.killstreakBest ?? data.killstreak;
|
||||
const lastSessionAt = data.lastSessionAt ?? null;
|
||||
const firstSessionAt = data.firstSessionAt ?? null;
|
||||
const historyVisible =
|
||||
data.killstreak > 0 || history.completedPlans > 0 || history.sessions > 0 || history.sets > 0;
|
||||
|
||||
@@ -404,39 +412,35 @@ export default function Dashboard() {
|
||||
{historyVisible && (
|
||||
<>
|
||||
<GroupLabel className="mb-2">Historia</GroupLabel>
|
||||
<div className="mb-4 grid grid-cols-2 gap-4 lg:grid-cols-4">
|
||||
{/* Jedna linia: Serie + Killstreak (razem 4/5) i Ukończone plany (1/5). */}
|
||||
<div className="mb-4 grid grid-cols-1 gap-4 sm:grid-cols-5">
|
||||
{/* Kafelek: łączna liczba serii + prawdziwy trend tygodniowy. */}
|
||||
<Card className="mb-0 flex min-w-0 flex-wrap items-end justify-between gap-x-8 gap-y-3 p-5 sm:col-span-2">
|
||||
<div className="min-w-0">
|
||||
<div className="text-[11px] font-bold uppercase tracking-[0.1em] text-dim">
|
||||
Serie
|
||||
</div>
|
||||
<div className="font-display text-[1.9rem] font-bold leading-tight tracking-[-0.02em] tabular-nums">
|
||||
{history.sets}
|
||||
</div>
|
||||
<div className="text-dim text-[0.8125rem]">
|
||||
łącznie · kreski: serie w 8 ostatnich tygodniach
|
||||
</div>
|
||||
</div>
|
||||
<WeekBars values={(data.weeklySets ?? []).map((w) => w.sets)} />
|
||||
</Card>
|
||||
<StatCard
|
||||
className="sm:col-span-2"
|
||||
label="Killstreak"
|
||||
value={data.killstreak > 0 ? data.killstreak : '—'}
|
||||
sub={`rekord: ${daysPlural(killstreakBest)}`}
|
||||
/>
|
||||
<StatCard label="Ukończone plany" value={history.completedPlans} />
|
||||
<StatCard
|
||||
label="Treningi"
|
||||
value={history.sessions}
|
||||
sub={lastSessionAt ? `ostatni: ${timeAgo(lastSessionAt)}` : undefined}
|
||||
className="sm:col-span-1"
|
||||
label="Ukończone plany"
|
||||
value={history.completedPlans}
|
||||
/>
|
||||
{firstSessionAt != null && (
|
||||
<StatCard
|
||||
label="Trenujesz od"
|
||||
value={daysSince(firstSessionAt)}
|
||||
sub={`od ${fmtDate(firstSessionAt)}`}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
{/* Szeroki kafelek: łączna liczba serii + prawdziwy trend tygodniowy. */}
|
||||
<Card className="mb-4 flex flex-wrap items-end justify-between gap-x-8 gap-y-3 p-5">
|
||||
<div className="min-w-0">
|
||||
<div className="text-[11px] font-bold uppercase tracking-[0.1em] text-dim">Serie</div>
|
||||
<div className="font-display text-[1.9rem] font-bold leading-tight tracking-[-0.02em] tabular-nums">
|
||||
{history.sets}
|
||||
</div>
|
||||
<div className="text-dim text-[0.8125rem]">
|
||||
łącznie · kreski: serie w 8 ostatnich tygodniach
|
||||
</div>
|
||||
</div>
|
||||
<WeekBars values={(data.weeklySets ?? []).map((w) => w.sets)} />
|
||||
</Card>
|
||||
</>
|
||||
)}
|
||||
|
||||
|
||||
@@ -137,17 +137,17 @@ describe('Dashboard — statystyki motywacyjne', () => {
|
||||
expect(await screen.findByText('brak treningów w tym tygodniu')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('sekcja „Historia": rekord passy, ostatni trening i „Trenujesz od”', async () => {
|
||||
it('sekcja „Historia": rekord passy, bez kart „Treningi" i „Trenujesz od"', async () => {
|
||||
mockApi(dashBody());
|
||||
const user = userEvent.setup();
|
||||
renderApp();
|
||||
await login(user);
|
||||
|
||||
expect(await screen.findByText('rekord: 5 dni')).toBeInTheDocument();
|
||||
expect(screen.getByText('ostatni: wczoraj')).toBeInTheDocument();
|
||||
expect(screen.getByText('Trenujesz od', { exact: true })).toBeInTheDocument();
|
||||
// Pierwsza sesja 29 dni temu => 30. dzień przygody (włącznie).
|
||||
expect(screen.getByText('30', { exact: true })).toBeInTheDocument();
|
||||
expect(screen.getByText('Ukończone plany', { 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();
|
||||
});
|
||||
|
||||
it('kafelek „Serie” renderuje prawdziwy wykres ośmiu tygodni', async () => {
|
||||
|
||||
@@ -22,7 +22,7 @@ test('udane logowanie przekierowuje na dashboard', async ({ page }) => {
|
||||
await expect(page.getByText('1/3', { exact: true })).toBeVisible();
|
||||
await expect(page.getByText('Historia', { exact: true })).toBeVisible();
|
||||
await expect(page.getByText('rekord: 5 dni')).toBeVisible();
|
||||
await expect(page.getByText('Trenujesz od', { exact: true })).toBeVisible();
|
||||
await expect(page.getByText('Ukończone plany', { exact: true })).toBeVisible();
|
||||
});
|
||||
|
||||
test('zapamiętaj mnie zapisuje e-mail i podpowiada go po wylogowaniu', async ({ page }) => {
|
||||
|
||||
Reference in New Issue
Block a user