|
1 | 1 |
|
2 | | -import React, { memo } from 'react'; |
| 2 | +import React, { memo, useMemo } from 'react'; |
3 | 3 |
|
4 | | -import { AlertTriangle, Calendar, Dumbbell, Trophy } from 'lucide-react'; |
| 4 | +import { Dumbbell, Trophy } from 'lucide-react'; |
| 5 | +import { WeeklySetsBodyIcon } from '../dashboard/weeklySets/WeeklySetsIcons'; |
5 | 6 |
|
6 | | -import type { DashboardInsights, PRInsights } from '../../utils/analysis/insights'; |
| 7 | +import type { DashboardInsights } from '../../utils/analysis/insights'; |
7 | 8 | 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'; |
37 | 12 |
|
38 | 13 | // Main Insights Panel Component |
39 | 14 | interface InsightsPanelProps { |
40 | 15 | insights: DashboardInsights; |
41 | | - totalWorkouts: number; |
42 | | - totalSets: number; |
43 | 16 | totalPRs: number; |
| 17 | + weightUnit: WeightUnit; |
| 18 | + weeklySetsDashboard: WeeklySetsDashboardResult | null; |
44 | 19 | } |
45 | 20 |
|
46 | 21 | export const InsightsPanel: React.FC<InsightsPanelProps> = memo(function InsightsPanel(props) { |
47 | 22 | const { |
48 | 23 | insights, |
49 | | - totalWorkouts, |
50 | | - totalSets, |
51 | 24 | totalPRs, |
| 25 | + weightUnit, |
| 26 | + weeklySetsDashboard, |
52 | 27 | } = 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]); |
54 | 43 |
|
55 | 44 | return ( |
56 | 45 | <div className="grid gap-2 grid-cols-2 lg:grid-cols-3"> |
57 | | - {/* Workouts */} |
| 46 | + {/* PRs */} |
58 | 47 | <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} |
65 | 54 | 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" |
69 | 58 | /> |
70 | 59 |
|
71 | | - {/* Sets This Week - hidden on mobile */} |
| 60 | + {/* Volume - desktop only */} |
72 | 61 | <div className="hidden lg:block"> |
73 | 62 | <KPICard |
74 | | - title="Sets" |
75 | | - value={rolling7d.current.totalSets} |
76 | | - subtitle="lst 7d" |
| 63 | + title="Volume" |
| 64 | + value={displayVolume} |
| 65 | + subtitle={`${volumeUnit} lst 7d`} |
77 | 66 | icon={Dumbbell} |
78 | 67 | iconColor="text-purple-400" |
79 | | - delta={rolling7d.sets ?? undefined} |
| 68 | + delta={rolling7d.volume ?? undefined} |
80 | 69 | deltaContext="vs prev 7d" |
81 | | - sparkline={setsSparkline} |
| 70 | + sparkline={weeklyVolumeSparkline} |
82 | 71 | sparklineColor="#a855f7" |
83 | | - sparklineTitle="Training volume over last 8 weeks" |
| 72 | + sparklineTitle="Weekly volume over last 4 weeks" |
84 | 73 | /> |
85 | 74 | </div> |
86 | 75 |
|
87 | | - {/* PRs */} |
| 76 | + {/* Weekly Sets */} |
88 | 77 | <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" |
98 | 88 | /> |
99 | 89 | </div> |
100 | 90 | ); |
|
0 commit comments