Skip to content

Commit f3516d3

Browse files
feat(05-02): add group summary in header
- Add groupSummaries useMemo to calculate totals per group - Sum volume and goal for all muscles in each group - Calculate group percentage (handle divide by zero) - Display group total sets in header with dynamic color - Color uses getVolumeColor for visual consistency with progress bars
1 parent 2156ff3 commit f3516d3

1 file changed

Lines changed: 38 additions & 4 deletions

File tree

src/ui/components/mobile/MobileMuscleList.tsx

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,31 @@ export function MobileMuscleList({
4141
const statsMap = useMemo(() => {
4242
return new Map<string, VolumeStatItem>(stats.map((s) => [s.name, s]));
4343
}, [stats]);
44+
45+
// Calculate group summaries for header display
46+
const groupSummaries = useMemo(() => {
47+
const summaries = new Map<
48+
string,
49+
{ totalVolume: number; totalGoal: number; percentage: number }
50+
>();
51+
52+
for (const group of UI_MUSCLE_GROUPS) {
53+
let totalVolume = 0;
54+
let totalGoal = 0;
55+
56+
for (const muscle of group.muscles) {
57+
const muscleStats = statsMap.get(muscle);
58+
totalVolume += muscleStats?.volume ?? 0;
59+
totalGoal += muscleStats?.goal ?? 0;
60+
}
61+
62+
const percentage = totalGoal > 0 ? (totalVolume / totalGoal) * 100 : 0;
63+
summaries.set(group.name, { totalVolume, totalGoal, percentage });
64+
}
65+
66+
return summaries;
67+
}, [statsMap]);
68+
4469
// Start with first group expanded (mobile-optimized: less initial scrolling)
4570
const [expandedGroups, setExpandedGroups] = useState<Set<string>>(() => {
4671
const firstGroup = UI_MUSCLE_GROUPS[0];
@@ -80,6 +105,9 @@ export function MobileMuscleList({
80105
<div className="space-y-2">
81106
{UI_MUSCLE_GROUPS.map((group) => {
82107
const isExpanded = expandedGroups.has(group.name);
108+
const summary = groupSummaries.get(group.name);
109+
const groupPercentage = summary?.percentage ?? 0;
110+
const groupVolume = summary?.totalVolume ?? 0;
83111

84112
return (
85113
<div
@@ -111,10 +139,16 @@ export function MobileMuscleList({
111139
{/* Group name */}
112140
<span className="font-medium text-white">{group.name}</span>
113141

114-
{/* Muscle count badge */}
115-
<span className="ml-auto text-xs text-primary-400">
116-
{group.muscles.length} muscles
117-
</span>
142+
{/* Group summary - total sets with color indicating progress */}
143+
<div className="ml-auto flex items-center gap-2">
144+
<span
145+
className="font-mono text-sm"
146+
style={{ color: getVolumeColor(groupPercentage) }}
147+
>
148+
{formatVolume(groupVolume)}
149+
</span>
150+
<span className="text-primary-400 text-xs">sets</span>
151+
</div>
118152
</button>
119153

120154
{/* Group content - conditionally rendered */}

0 commit comments

Comments
 (0)