Dashboard: Postep realizacji w stylu killstreak (kreska trendu rosnaca/opadajaca wg nadmiaru/deficytu)

This commit is contained in:
Tilumca
2026-10-15 02:28:35 +02:00
parent 6968ca0ad3
commit 007f1509b3
2 changed files with 46 additions and 34 deletions

View File

@@ -1,6 +1,6 @@
import { useEffect, useState, type ReactNode } from 'react';
import { Link } from 'react-router-dom';
import { CalendarPlus, Dumbbell, Flame, Megaphone, Minus, Play, TrendingDown, TrendingUp } from 'lucide-react';
import { CalendarPlus, Dumbbell, Flame, Megaphone, Play } from 'lucide-react';
import type { LucideIcon } from 'lucide-react';
import { useActiveSession, useDashboard, useFeed } from '../api/queries';
import { FeedItemRow } from '../components/FeedItemRow';
@@ -40,18 +40,31 @@ function planWeekNo(startDate: string | null): number | null {
}
/* Dekoracyjna sparkline (aria-hidden) — kształt deterministyczny od wartości. */
function Sparkline({ value }: { value: number }) {
const n = Math.max(2, Math.min(12, value));
/* Kreska trendu pod statystyką: rośnie (up), opada (down) lub płasko (flat). */
function Sparkline({
value,
direction = 'up',
color = 'accent',
}: {
value: number;
direction?: 'up' | 'down' | 'flat';
color?: 'accent' | 'danger';
}) {
const n = Math.max(2, Math.min(12, Math.abs(value) || 2));
const w = 86;
const h = 22;
const pts: string[] = [];
for (let i = 0; i < n; i++) {
const x = 1 + (i * (w - 6)) / Math.max(1, n - 1);
const t = i / Math.max(1, n - 1);
const x = 1 + t * (w - 6);
const drop = Math.sin(i * 1.7 + value) * 3;
const y = h - 4 - (i / Math.max(1, n - 1)) * (h - 9) + drop;
const base =
direction === 'down' ? 4 + t * (h - 9) : direction === 'flat' ? (h - 2) / 2 + drop * 0.3 : h - 4 - t * (h - 9);
const y = direction === 'flat' ? base : base + drop;
pts.push(`${x.toFixed(1)},${Math.max(2, Math.min(h - 2, y)).toFixed(1)}`);
}
const last = pts[pts.length - 1].split(',');
const stroke = color === 'danger' ? 'var(--danger)' : 'var(--accent)';
return (
<svg
aria-hidden="true"
@@ -63,12 +76,12 @@ function Sparkline({ value }: { value: number }) {
>
<polyline
points={pts.join(' ')}
stroke="var(--accent)"
stroke={stroke}
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
<circle cx={last[0]} cy={last[1]} r="2.4" fill="var(--accent)" />
<circle cx={last[0]} cy={last[1]} r="2.4" fill={stroke} />
</svg>
);
}
@@ -116,7 +129,7 @@ function StatCard({
}: {
label: string;
value: ReactNode;
tone?: 'default' | 'danger' | 'positive';
tone?: 'default' | 'danger';
children?: ReactNode;
}) {
return (
@@ -124,7 +137,7 @@ function StatCard({
<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 tabular-nums tracking-[-0.02em] ${
tone === 'danger' ? 'text-danger' : tone === 'positive' ? 'text-accent-text' : ''
tone === 'danger' ? 'text-danger' : ''
}`}
>
{value}
@@ -375,37 +388,37 @@ export default function Dashboard() {
</StatCard>
<StatCard
label="Postęp realizacji"
value={(() => {
// Pojedynczy wskaźnik: ile serii powyżej/poniżej planu (nadmiar − deficyt).
if (!data.extra || !data.missing) return '—';
const net = data.extra.sets - data.missing.sets;
const Icon = net > 0 ? TrendingUp : net < 0 ? TrendingDown : Minus;
return (
<>
<Icon className="h-5 w-5 shrink-0" aria-hidden="true" />
{net > 0 ? `+${net}` : net}
</>
);
})()}
value={
!data.extra || !data.missing
? '—'
: data.extra.sets - data.missing.sets > 0
? `+${data.extra.sets - data.missing.sets}`
: `${data.extra.sets - data.missing.sets}`
}
tone={
!data.extra || !data.missing
? 'default'
: data.extra.sets - data.missing.sets < 0
? 'danger'
: data.extra.sets - data.missing.sets > 0
? 'positive'
: 'default'
: 'default'
}
>
<div className="text-dim text-[0.75rem]">
{!data.extra || !data.missing
? 'brak aktywnego planu'
: data.extra.sets - data.missing.sets > 0
? 'serii ponad plan'
: data.extra.sets - data.missing.sets < 0
? 'serii poniżej planu'
: 'serii — zgodnie z planem'}
</div>
{/* Jedna linia trendu: rośnie przy nadmiarze, opada przy deficycie (jak killstreak). */}
{data.extra && data.missing ? (
<Sparkline
value={data.extra.sets - data.missing.sets}
direction={
data.extra.sets - data.missing.sets > 0
? 'up'
: data.extra.sets - data.missing.sets < 0
? 'down'
: 'flat'
}
color={data.extra.sets - data.missing.sets < 0 ? 'danger' : 'accent'}
/>
) : (
<div className="text-dim text-[0.75rem]">brak aktywnego planu</div>
)}
</StatCard>
</div>

View File

@@ -20,7 +20,6 @@ test('udane logowanie przekierowuje na dashboard', async ({ page }) => {
await expect(page.getByText('Plan testowy')).toBeVisible();
await expect(page.getByText('Postęp realizacji')).toBeVisible();
await expect(page.getByText('+4')).toBeVisible();
await expect(page.getByText('serii ponad plan')).toBeVisible();
});
test('zapamiętaj mnie zapisuje e-mail i podpowiada go po wylogowaniu', async ({ page }) => {