Skip to content

Commit 58c3570

Browse files
committed
feat: redesign KPI row with PRs, Volume (desktop only), and Weekly Sets cards
1 parent 9a7b3ba commit 58c3570

1 file changed

Lines changed: 54 additions & 64 deletions

File tree

frontend/components/insights/InsightsPanel.tsx

Lines changed: 54 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,90 @@
11

2-
import React, { memo } from 'react';
2+
import React, { memo, useMemo } from 'react';
33

4-
import { AlertTriangle, Calendar, Dumbbell, Trophy } from 'lucide-react';
4+
import { Dumbbell, Trophy } from 'lucide-react';
5+
import { WeeklySetsBodyIcon } from '../dashboard/weeklySets/WeeklySetsIcons';
56

6-
import type { DashboardInsights, PRInsights } from '../../utils/analysis/insights';
7+
import type { DashboardInsights } from '../../utils/analysis/insights';
78
import { KPICard } from './KPICard';
8-
9-
// PR Status Badge
10-
const PRStatusBadge: React.FC<{ prInsights: PRInsights }> = ({ prInsights }) => {
11-
const { daysSinceLastPR, prDrought } = prInsights;
12-
13-
if (daysSinceLastPR < 0) {
14-
return (
15-
<span className="text-[10px] text-slate-500">Chase your first PR</span>
16-
);
17-
}
18-
19-
if (prDrought) {
20-
return (
21-
<div className="inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-amber-500/10">
22-
<AlertTriangle className="w-3 h-3 text-amber-400 flex-shrink-0" />
23-
<span className="text-[10px] font-bold text-amber-400 whitespace-nowrap">{daysSinceLastPR}d drought</span>
24-
</div>
25-
);
26-
}
27-
28-
return (
29-
<div className="inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-emerald-500/10">
30-
<Trophy className="w-3 h-3 text-emerald-400 flex-shrink-0" />
31-
<span className="text-[10px] font-bold text-emerald-400 whitespace-nowrap">
32-
{daysSinceLastPR === 0 ? 'PR today!' : `${daysSinceLastPR}d ago`}
33-
</span>
34-
</div>
35-
);
36-
};
9+
import { getDisplayVolume } from '../../utils/format/volumeDisplay';
10+
import type { WeightUnit } from '../../utils/storage/localStorage';
11+
import type { WeeklySetsDashboardResult } from '../../utils/muscle/analytics/dashboardWeeklySets';
3712

3813
// Main Insights Panel Component
3914
interface InsightsPanelProps {
4015
insights: DashboardInsights;
41-
totalWorkouts: number;
42-
totalSets: number;
4316
totalPRs: number;
17+
weightUnit: WeightUnit;
18+
weeklySetsDashboard: WeeklySetsDashboardResult | null;
4419
}
4520

4621
export const InsightsPanel: React.FC<InsightsPanelProps> = memo(function InsightsPanel(props) {
4722
const {
4823
insights,
49-
totalWorkouts,
50-
totalSets,
5124
totalPRs,
25+
weightUnit,
26+
weeklySetsDashboard,
5227
} = props;
53-
const { rolling7d, streakInfo, prInsights, volumeSparkline, workoutSparkline, prSparkline, setsSparkline, consistencySparkline } = insights;
28+
const { rolling7d, weeklyVolumeSparkline, prSparkline, muscleAvgSparkline } = insights;
29+
30+
const displayVolume = getDisplayVolume(rolling7d.current.totalVolume, weightUnit, { round: 'int' });
31+
const volumeUnit = weightUnit === 'kg' ? 'kg' : 'lbs';
32+
33+
const weeklySetsAvg = useMemo(() => {
34+
if (!weeklySetsDashboard) return 0;
35+
const volumes = weeklySetsDashboard.heatmap.volumes;
36+
let sum = 0;
37+
let count = 0;
38+
for (const v of volumes.values()) {
39+
if (v > 0) { sum += v; count++; }
40+
}
41+
return count > 0 ? Math.round((sum / count) * 10) / 10 : 0;
42+
}, [weeklySetsDashboard]);
5443

5544
return (
5645
<div className="grid gap-2 grid-cols-2 lg:grid-cols-3">
57-
{/* Workouts */}
46+
{/* PRs */}
5847
<KPICard
59-
title="Lst 7d"
60-
value={rolling7d.current.totalWorkouts}
61-
subtitle="workouts"
62-
icon={Calendar}
63-
iconColor="text-blue-400"
64-
delta={rolling7d.workouts ?? undefined}
48+
title="PRs"
49+
value={totalPRs}
50+
subtitle="total"
51+
icon={Trophy}
52+
iconColor="text-yellow-400"
53+
delta={rolling7d.prs ?? undefined}
6554
deltaContext="vs prev 7d"
66-
sparkline={workoutSparkline}
67-
sparklineColor="#3b82f6"
68-
sparklineTitle="Workout frequency over last 8 weeks"
55+
sparkline={prSparkline}
56+
sparklineColor="#eab308"
57+
sparklineTitle="Personal records over last 4 weeks"
6958
/>
7059

71-
{/* Sets This Week - hidden on mobile */}
60+
{/* Volume - desktop only */}
7261
<div className="hidden lg:block">
7362
<KPICard
74-
title="Sets"
75-
value={rolling7d.current.totalSets}
76-
subtitle="lst 7d"
63+
title="Volume"
64+
value={displayVolume}
65+
subtitle={`${volumeUnit} lst 7d`}
7766
icon={Dumbbell}
7867
iconColor="text-purple-400"
79-
delta={rolling7d.sets ?? undefined}
68+
delta={rolling7d.volume ?? undefined}
8069
deltaContext="vs prev 7d"
81-
sparkline={setsSparkline}
70+
sparkline={weeklyVolumeSparkline}
8271
sparklineColor="#a855f7"
83-
sparklineTitle="Training volume over last 8 weeks"
72+
sparklineTitle="Weekly volume over last 4 weeks"
8473
/>
8574
</div>
8675

87-
{/* PRs */}
76+
{/* Weekly Sets */}
8877
<KPICard
89-
title="PRs"
90-
value={totalPRs}
91-
subtitle="total"
92-
icon={Trophy}
93-
iconColor="text-yellow-400"
94-
sparkline={prSparkline}
95-
sparklineColor="#eab308"
96-
sparklineTitle="Personal records over last 8 weeks"
97-
badge={<PRStatusBadge prInsights={prInsights} />}
78+
title="Weekly Sets"
79+
value={weeklySetsAvg}
80+
subtitle="sets / muscle"
81+
icon={WeeklySetsBodyIcon}
82+
iconColor="text-cyan-400"
83+
delta={rolling7d.sets ?? undefined}
84+
deltaContext="vs prev 7d"
85+
sparkline={muscleAvgSparkline}
86+
sparklineColor="#22c55e"
87+
sparklineTitle="Average sets per exercise over last 4 weeks"
9888
/>
9989
</div>
10090
);

0 commit comments

Comments
 (0)