@titan-design/react-ui 0.2.7 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/dist/bodymap-BhG55xHM.d.mts +318 -0
  2. package/dist/bodymap-BhG55xHM.d.ts +318 -0
  3. package/dist/bodymap.d.mts +3 -0
  4. package/dist/bodymap.d.ts +3 -0
  5. package/dist/bodymap.js +3014 -0
  6. package/dist/bodymap.js.map +1 -0
  7. package/dist/bodymap.mjs +1088 -0
  8. package/dist/bodymap.mjs.map +1 -0
  9. package/dist/chunk-2SISKTWM.mjs +1027 -0
  10. package/dist/chunk-2SISKTWM.mjs.map +1 -0
  11. package/dist/{chunk-5SSKGS6E.mjs → chunk-7XPB4NAO.mjs} +124 -4
  12. package/dist/chunk-7XPB4NAO.mjs.map +1 -0
  13. package/dist/{chunk-3VLOBS6O.mjs → chunk-SNVKL5WZ.mjs} +42 -5
  14. package/dist/chunk-SNVKL5WZ.mjs.map +1 -0
  15. package/dist/index.d.mts +416 -250
  16. package/dist/index.d.ts +416 -250
  17. package/dist/index.js +1567 -1123
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs +1491 -2201
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/theme/index.d.mts +288 -2
  22. package/dist/theme/index.d.ts +288 -2
  23. package/dist/theme/index.js +159 -2
  24. package/dist/theme/index.js.map +1 -1
  25. package/dist/theme/index.mjs +2 -2
  26. package/dist/theme/tokens-css.d.mts +5 -3
  27. package/dist/theme/tokens-css.d.ts +5 -3
  28. package/dist/theme/tokens-css.js +318 -9
  29. package/dist/theme/tokens-css.js.map +1 -1
  30. package/dist/theme/tokens-css.mjs +1 -1
  31. package/dist/theme/tokens-css.mjs.map +1 -1
  32. package/package.json +10 -1
  33. package/src/bodymap.ts +37 -0
  34. package/src/components/custom/Table/Table.test.tsx +27 -0
  35. package/src/components/custom/Table/Table.tsx +33 -17
  36. package/src/components/custom/Workout/ActiveWorkoutPage.stories.tsx +118 -0
  37. package/src/components/custom/Workout/ActiveWorkoutPage.test.tsx +171 -0
  38. package/src/components/custom/Workout/ActiveWorkoutPage.tsx +442 -0
  39. package/src/components/custom/Workout/BodyMap.tsx +7 -9
  40. package/src/components/custom/Workout/BodyMapDetailPanel.tsx +25 -29
  41. package/src/components/custom/Workout/CapacityBandChart.tsx +2 -3
  42. package/src/components/custom/Workout/ExerciseCard.test.tsx +24 -0
  43. package/src/components/custom/Workout/ExerciseCard.tsx +24 -26
  44. package/src/components/custom/Workout/ExerciseDetailPage.stories.tsx +225 -0
  45. package/src/components/custom/Workout/ExerciseDetailPage.test.tsx +128 -0
  46. package/src/components/custom/Workout/ExerciseDetailPage.tsx +624 -0
  47. package/src/components/custom/Workout/InputBar.tsx +10 -12
  48. package/src/components/custom/Workout/MesoCard.tsx +2 -4
  49. package/src/components/custom/Workout/MesoProgressBar.test.tsx +12 -0
  50. package/src/components/custom/Workout/MesoProgressBar.tsx +5 -1
  51. package/src/components/custom/Workout/MesoStatusCard.tsx +17 -15
  52. package/src/components/custom/Workout/MuscleGroupChip.tsx +2 -4
  53. package/src/components/custom/Workout/PlaceholderStrip.tsx +2 -4
  54. package/src/components/custom/Workout/PrHistoryModal.tsx +12 -14
  55. package/src/components/custom/Workout/ProgramPlanningPage.stories.tsx +257 -0
  56. package/src/components/custom/Workout/ProgramPlanningPage.test.tsx +142 -0
  57. package/src/components/custom/Workout/ProgramPlanningPage.tsx +418 -0
  58. package/src/components/custom/Workout/ReadinessCheck.tsx +13 -12
  59. package/src/components/custom/Workout/RestTimer.test.tsx +10 -0
  60. package/src/components/custom/Workout/RestTimer.tsx +12 -9
  61. package/src/components/custom/Workout/SetRow.tsx +16 -19
  62. package/src/components/custom/Workout/StatusDot.tsx +1 -0
  63. package/src/components/custom/Workout/StrengthTrendChart.tsx +15 -17
  64. package/src/components/custom/Workout/TempoBar.stories.tsx +95 -0
  65. package/src/components/custom/Workout/TempoBar.test.tsx +103 -0
  66. package/src/components/custom/Workout/TempoBar.tsx +215 -0
  67. package/src/components/custom/Workout/TempoDisplay.tsx +3 -1
  68. package/src/components/custom/Workout/TrainingStatusPage.stories.tsx +212 -0
  69. package/src/components/custom/Workout/TrainingStatusPage.test.tsx +131 -0
  70. package/src/components/custom/Workout/TrainingStatusPage.tsx +312 -0
  71. package/src/components/custom/Workout/VelocityStrip.test.tsx +10 -0
  72. package/src/components/custom/Workout/VelocityStrip.tsx +19 -16
  73. package/src/components/custom/Workout/WeekRow.tsx +2 -1
  74. package/src/components/custom/Workout/WorkoutCard.tsx +3 -6
  75. package/src/components/custom/Workout/index.ts +80 -32
  76. package/src/test/nativewind-stub.ts +13 -0
  77. package/src/theme/ThemeProvider.test.tsx +24 -0
  78. package/src/theme/ThemeProvider.tsx +50 -0
  79. package/src/theme/config.completeness.test.ts +77 -0
  80. package/src/theme/config.ts +151 -0
  81. package/src/theme/index.ts +2 -0
  82. package/src/theme/manifest/design-freeze.test.ts +155 -0
  83. package/src/theme/manifest/extract-css-properties.fixture.html +29 -0
  84. package/src/theme/manifest/extract-css-properties.test.ts +112 -0
  85. package/src/theme/resolve-color.ts +19 -0
  86. package/src/theme/tokens-css.ts +5 -3
  87. package/src/theme/workout-tokens.ts +12 -14
  88. package/src/utils/index.ts +10 -0
  89. package/src/utils/workout-format.test.ts +81 -0
  90. package/src/utils/workout-format.ts +83 -0
  91. package/dist/chunk-3VLOBS6O.mjs.map +0 -1
  92. package/dist/chunk-5SSKGS6E.mjs.map +0 -1
@@ -1,6 +1,7 @@
1
1
  // Font mapping: font-heading=Space Grotesk, font-body=Nunito Sans (UI), font-sans=Inter (body)
2
2
  import { useState, useCallback } from 'react'
3
3
  import { View, Text, Pressable, type ViewProps } from 'react-native'
4
+ import { roundTempo } from '../../../utils/workout-format'
4
5
 
5
6
  export interface TempoDisplayProps extends ViewProps {
6
7
  /** Tempo values: [eccentric, pauseBottom, concentric, pauseTop] in seconds */
@@ -76,7 +77,8 @@ export function TempoDisplay({
76
77
  ...props
77
78
  }: TempoDisplayProps) {
78
79
  const [showTooltip, setShowTooltip] = useState(false)
79
- const [eccentric, pauseBottom, concentric, pauseTop] = tempo
80
+ // Round exact (unrounded) tempo seconds to the 1-dp display granularity.
81
+ const [eccentric, pauseBottom, concentric, pauseTop] = roundTempo(tempo)
80
82
  const isSm = size === 'sm'
81
83
  const fontSize = isSm ? 9 : 11
82
84
  const monoColor = TEXT_TERTIARY
@@ -0,0 +1,212 @@
1
+ import type { Meta, StoryObj } from '@storybook/react-vite'
2
+ import { TrainingStatusPage, type TrainingStatusMuscle } from './TrainingStatusPage'
3
+ import { MesoStatusCardProps } from './MesoStatusCard'
4
+ import { MuscleGroup } from './muscleTaxonomy'
5
+
6
+ const meso: MesoStatusCardProps = {
7
+ mesoName: 'Hypertrophy Block',
8
+ mesoSubtitle: 'Week 6 of 8 · Upper/Lower',
9
+ statusBadge: { label: 'On Track', variant: 'success' },
10
+ metrics: [
11
+ { label: 'Weekly Volume', value: '112 sets' },
12
+ { label: 'Avg Intensity', value: 'RPE 8.2' },
13
+ { label: 'Sessions', value: '5 / 5' },
14
+ { label: 'Deload', value: 'in 2 weeks' },
15
+ ],
16
+ gauges: [
17
+ { label: 'Volume', level: 0.68, sublabel: 'Actual' },
18
+ { label: 'Fatigue', level: 0.55, sublabel: 'Managed' },
19
+ ],
20
+ coaching: {
21
+ text: 'Push volume on lagging back and rear delts before the deload.',
22
+ highlights: ['back and rear delts'],
23
+ },
24
+ nextTarget: { icon: '🎯', text: 'Add 2 sets to pulling this week' },
25
+ }
26
+
27
+ const muscles: TrainingStatusMuscle[] = [
28
+ {
29
+ muscleGroup: MuscleGroup.CHEST,
30
+ displayName: 'Chest',
31
+ side: 'front',
32
+ intensity: 0.72,
33
+ volumeStatus: 'productive',
34
+ weeklySets: 14,
35
+ landmarks: { mev: 8, mav: 14, mrv: 20 },
36
+ lastTrained: '2 days ago',
37
+ weeklyHistory: [8, 10, 12, 11, 13, 14],
38
+ contributingExercises: [
39
+ { name: 'Barbell Bench Press', sets: 4, contributionWeight: 1 },
40
+ { name: 'Incline Dumbbell Press', sets: 3, contributionWeight: 1 },
41
+ { name: 'Cable Fly', sets: 3, contributionWeight: 0.75 },
42
+ ],
43
+ upcomingExercises: [{ name: 'Machine Chest Press', workoutName: 'Push B', sets: 3 }],
44
+ },
45
+ {
46
+ muscleGroup: MuscleGroup.FRONT_DELTS,
47
+ displayName: 'Front Delts',
48
+ side: 'front',
49
+ intensity: 0.45,
50
+ volumeStatus: 'maintenance',
51
+ weeklySets: 5,
52
+ landmarks: { mev: 2, mav: 6, mrv: 10 },
53
+ lastTrained: '2 days ago',
54
+ weeklyHistory: [4, 5, 5, 5],
55
+ },
56
+ {
57
+ muscleGroup: MuscleGroup.SIDE_DELTS,
58
+ displayName: 'Side Delts',
59
+ side: 'front',
60
+ intensity: 0.6,
61
+ volumeStatus: 'productive',
62
+ weeklySets: 12,
63
+ landmarks: { mev: 6, mav: 14, mrv: 22 },
64
+ lastTrained: '1 day ago',
65
+ weeklyHistory: [8, 9, 10, 11, 12],
66
+ },
67
+ {
68
+ muscleGroup: MuscleGroup.BICEPS,
69
+ displayName: 'Biceps',
70
+ side: 'front',
71
+ intensity: 0.3,
72
+ volumeStatus: 'under',
73
+ weeklySets: 3,
74
+ landmarks: { mev: 4, mav: 10, mrv: 18 },
75
+ lastTrained: '4 days ago',
76
+ weeklyHistory: [2, 3, 3, 3],
77
+ },
78
+ {
79
+ muscleGroup: MuscleGroup.ABS,
80
+ displayName: 'Abs',
81
+ side: 'front',
82
+ intensity: 0.4,
83
+ volumeStatus: 'maintenance',
84
+ weeklySets: 6,
85
+ landmarks: { mev: 0, mav: 8, mrv: 16 },
86
+ lastTrained: '1 day ago',
87
+ },
88
+ {
89
+ muscleGroup: MuscleGroup.QUADS,
90
+ displayName: 'Quads',
91
+ side: 'front',
92
+ intensity: 0.95,
93
+ volumeStatus: 'over',
94
+ weeklySets: 20,
95
+ landmarks: { mev: 6, mav: 12, mrv: 18 },
96
+ lastTrained: 'today',
97
+ weeklyHistory: [12, 14, 16, 18, 20],
98
+ contributingExercises: [
99
+ { name: 'Back Squat', sets: 5, contributionWeight: 1 },
100
+ { name: 'Leg Press', sets: 4, contributionWeight: 0.85 },
101
+ ],
102
+ },
103
+ {
104
+ muscleGroup: MuscleGroup.LATS,
105
+ displayName: 'Lats',
106
+ side: 'back',
107
+ intensity: 0.58,
108
+ volumeStatus: 'productive',
109
+ weeklySets: 11,
110
+ landmarks: { mev: 8, mav: 14, mrv: 20 },
111
+ lastTrained: '3 days ago',
112
+ weeklyHistory: [7, 8, 9, 10, 11],
113
+ contributingExercises: [
114
+ { name: 'Pull-Up', sets: 4, contributionWeight: 1 },
115
+ { name: 'Barbell Row', sets: 4, contributionWeight: 0.9 },
116
+ ],
117
+ },
118
+ {
119
+ muscleGroup: MuscleGroup.UPPER_BACK,
120
+ displayName: 'Upper Back',
121
+ side: 'back',
122
+ intensity: 0.5,
123
+ volumeStatus: 'maintenance',
124
+ weeklySets: 8,
125
+ landmarks: { mev: 6, mav: 12, mrv: 18 },
126
+ lastTrained: '3 days ago',
127
+ },
128
+ {
129
+ muscleGroup: MuscleGroup.REAR_DELTS,
130
+ displayName: 'Rear Delts',
131
+ side: 'back',
132
+ intensity: 0.28,
133
+ volumeStatus: 'under',
134
+ weeklySets: 4,
135
+ landmarks: { mev: 6, mav: 12, mrv: 18 },
136
+ lastTrained: '5 days ago',
137
+ weeklyHistory: [2, 3, 3, 4],
138
+ },
139
+ {
140
+ muscleGroup: MuscleGroup.TRICEPS,
141
+ displayName: 'Triceps',
142
+ side: 'back',
143
+ intensity: 0.65,
144
+ volumeStatus: 'productive',
145
+ weeklySets: 9,
146
+ landmarks: { mev: 4, mav: 8, mrv: 14 },
147
+ lastTrained: '2 days ago',
148
+ weeklyHistory: [6, 7, 8, 9],
149
+ },
150
+ {
151
+ muscleGroup: MuscleGroup.GLUTES,
152
+ displayName: 'Glutes',
153
+ side: 'back',
154
+ intensity: 0.7,
155
+ volumeStatus: 'productive',
156
+ weeklySets: 10,
157
+ landmarks: { mev: 4, mav: 10, mrv: 16 },
158
+ lastTrained: 'today',
159
+ },
160
+ {
161
+ muscleGroup: MuscleGroup.HAMSTRINGS,
162
+ displayName: 'Hamstrings',
163
+ side: 'back',
164
+ intensity: 0.55,
165
+ volumeStatus: 'productive',
166
+ weeklySets: 9,
167
+ landmarks: { mev: 4, mav: 10, mrv: 16 },
168
+ lastTrained: 'today',
169
+ weeklyHistory: [6, 7, 8, 9],
170
+ },
171
+ {
172
+ muscleGroup: MuscleGroup.CALVES,
173
+ displayName: 'Calves',
174
+ side: 'back',
175
+ intensity: 0.2,
176
+ volumeStatus: 'under',
177
+ weeklySets: 3,
178
+ landmarks: { mev: 6, mav: 10, mrv: 16 },
179
+ lastTrained: '6 days ago',
180
+ },
181
+ ]
182
+
183
+ const meta: Meta<typeof TrainingStatusPage> = {
184
+ title: 'Custom/Workout/TrainingStatusPage',
185
+ component: TrainingStatusPage,
186
+ parameters: { layout: 'fullscreen' },
187
+ tags: ['autodocs'],
188
+ args: { title: 'Training Status', meso, muscles },
189
+ }
190
+
191
+ export default meta
192
+ type Story = StoryObj<typeof TrainingStatusPage>
193
+
194
+ export const Default: Story = {}
195
+
196
+ export const NeedsAttention: Story = {
197
+ args: {
198
+ meso: {
199
+ ...meso,
200
+ statusBadge: { label: 'Behind', variant: 'warning' },
201
+ coaching: {
202
+ text: 'Volume is trailing target — add a pulling session this week.',
203
+ highlights: ['add a pulling session'],
204
+ },
205
+ },
206
+ muscles: muscles.map((m) =>
207
+ m.side === 'back'
208
+ ? { ...m, volumeStatus: 'under', weeklySets: Math.max(2, m.weeklySets - 4) }
209
+ : m
210
+ ),
211
+ },
212
+ }
@@ -0,0 +1,131 @@
1
+ import { describe, it, expect } from 'vitest'
2
+ import { render, screen, fireEvent } from '@testing-library/react'
3
+ import {
4
+ TrainingStatusPage,
5
+ deriveTrainingSummary,
6
+ toBodyMapData,
7
+ type TrainingStatusMuscle,
8
+ } from './TrainingStatusPage'
9
+ import { type MesoStatusCardProps } from './MesoStatusCard'
10
+ import { MuscleGroup } from './muscleTaxonomy'
11
+
12
+ const meso: MesoStatusCardProps = {
13
+ mesoName: 'Hypertrophy Block',
14
+ mesoSubtitle: 'Week 6 of 8',
15
+ statusBadge: { label: 'On Track', variant: 'success' },
16
+ metrics: [{ label: 'Volume', value: '112 sets' }],
17
+ gauges: [{ label: 'Volume', level: 0.68 }],
18
+ }
19
+
20
+ const muscles: TrainingStatusMuscle[] = [
21
+ {
22
+ muscleGroup: MuscleGroup.CHEST,
23
+ displayName: 'Chest',
24
+ side: 'front',
25
+ intensity: 0.7,
26
+ volumeStatus: 'productive',
27
+ weeklySets: 14,
28
+ landmarks: { mev: 8, mav: 14, mrv: 20 },
29
+ lastTrained: '2 days ago',
30
+ weeklyHistory: [10, 12, 14],
31
+ },
32
+ {
33
+ muscleGroup: MuscleGroup.BICEPS,
34
+ displayName: 'Biceps',
35
+ side: 'front',
36
+ intensity: 0.3,
37
+ volumeStatus: 'under',
38
+ weeklySets: 3,
39
+ landmarks: { mev: 4, mav: 10, mrv: 18 },
40
+ },
41
+ {
42
+ muscleGroup: MuscleGroup.LATS,
43
+ displayName: 'Lats',
44
+ side: 'back',
45
+ intensity: 0.6,
46
+ volumeStatus: 'productive',
47
+ weeklySets: 11,
48
+ landmarks: { mev: 8, mav: 14, mrv: 20 },
49
+ },
50
+ {
51
+ muscleGroup: MuscleGroup.QUADS,
52
+ displayName: 'Quads',
53
+ side: 'front',
54
+ intensity: 0.95,
55
+ volumeStatus: 'over',
56
+ weeklySets: 20,
57
+ landmarks: { mev: 6, mav: 12, mrv: 18 },
58
+ },
59
+ ]
60
+
61
+ describe('deriveTrainingSummary', () => {
62
+ it('sums weekly sets and counts muscles per volume status', () => {
63
+ const summary = deriveTrainingSummary(muscles)
64
+ expect(summary.totalWeeklySets).toBe(48)
65
+ expect(summary.trackedMuscles).toBe(4)
66
+ expect(summary.statusCounts).toEqual({
67
+ under: 1,
68
+ maintenance: 0,
69
+ productive: 2,
70
+ over: 1,
71
+ })
72
+ })
73
+
74
+ it('returns zeroed counts for an empty muscle list', () => {
75
+ const summary = deriveTrainingSummary([])
76
+ expect(summary.totalWeeklySets).toBe(0)
77
+ expect(summary.trackedMuscles).toBe(0)
78
+ expect(summary.statusCounts).toEqual({ under: 0, maintenance: 0, productive: 0, over: 0 })
79
+ })
80
+ })
81
+
82
+ describe('toBodyMapData', () => {
83
+ it('keeps only the requested side and projects heatmap fields', () => {
84
+ const front = toBodyMapData(muscles, 'front')
85
+ expect(front.map((d) => d.muscleGroup)).toEqual([
86
+ MuscleGroup.CHEST,
87
+ MuscleGroup.BICEPS,
88
+ MuscleGroup.QUADS,
89
+ ])
90
+ expect(front[0]).toEqual({
91
+ muscleGroup: MuscleGroup.CHEST,
92
+ intensity: 0.7,
93
+ volumeStatus: 'productive',
94
+ weeklySets: 14,
95
+ })
96
+ })
97
+
98
+ it('filters to the back side', () => {
99
+ const back = toBodyMapData(muscles, 'back')
100
+ expect(back.map((d) => d.muscleGroup)).toEqual([MuscleGroup.LATS])
101
+ })
102
+ })
103
+
104
+ describe('TrainingStatusPage', () => {
105
+ it('renders the banner, summary cards, and both body maps', () => {
106
+ render(<TrainingStatusPage meso={meso} muscles={muscles} />)
107
+ expect(screen.getByTestId('training-status-page')).toBeInTheDocument()
108
+ expect(screen.getByTestId('meso-status-card')).toBeInTheDocument()
109
+ expect(screen.getByTestId('training-status-page-summary-total')).toHaveTextContent('48')
110
+ expect(screen.getByTestId('training-status-page-summary-productive')).toHaveTextContent('2')
111
+ expect(screen.getByTestId('training-status-page-bodymap-front')).toBeInTheDocument()
112
+ expect(screen.getByTestId('training-status-page-bodymap-back')).toBeInTheDocument()
113
+ })
114
+
115
+ it('uses a custom title when provided', () => {
116
+ render(<TrainingStatusPage title="Weekly Volume" meso={meso} muscles={muscles} />)
117
+ expect(screen.getByTestId('training-status-page-title')).toHaveTextContent('Weekly Volume')
118
+ })
119
+
120
+ it('opens the detail panel for a tapped muscle and closes it again', () => {
121
+ render(<TrainingStatusPage meso={meso} muscles={muscles} />)
122
+ expect(screen.queryByTestId('body-map-detail-panel')).not.toBeInTheDocument()
123
+
124
+ fireEvent.click(screen.getByTestId('body-map-muscle-chest'))
125
+ expect(screen.getByTestId('body-map-detail-panel')).toBeInTheDocument()
126
+ expect(screen.getByTestId('body-map-detail-panel-title')).toHaveTextContent('Chest')
127
+
128
+ fireEvent.click(screen.getByTestId('body-map-detail-panel-close'))
129
+ expect(screen.queryByTestId('body-map-detail-panel')).not.toBeInTheDocument()
130
+ })
131
+ })
@@ -0,0 +1,312 @@
1
+ // Font mapping: font-heading=Space Grotesk, font-body=Nunito Sans (UI), font-sans=Inter (body)
2
+ import { useMemo, useState } from 'react'
3
+ import { View, Text, type ViewProps } from 'react-native'
4
+ import { BodyMap, type BodyMapData } from './BodyMap'
5
+ import {
6
+ BodyMapDetailPanel,
7
+ type ContributingExercise,
8
+ type UpcomingExercise,
9
+ } from './BodyMapDetailPanel'
10
+ import { MesoStatusCard, type MesoStatusCardProps } from './MesoStatusCard'
11
+ import {
12
+ MuscleGroup,
13
+ VOLUME_STATUS_LABELS,
14
+ getHeatmapColor,
15
+ type VolumeLandmarks,
16
+ type VolumeStatus,
17
+ } from './muscleTaxonomy'
18
+
19
+ /** Volume statuses in display order for the legend and summary cards. */
20
+ const STATUS_ORDER: VolumeStatus[] = ['under', 'maintenance', 'productive', 'over']
21
+
22
+ /** One muscle's full volume picture — feeds the body maps and the detail panel. */
23
+ export interface TrainingStatusMuscle {
24
+ /** Detailed muscle group (drives the SVG heatmap + panel identity). */
25
+ muscleGroup: MuscleGroup
26
+ /** Human-readable name for the legend, summary, and panel title. */
27
+ displayName: string
28
+ /** Which body-map view the muscle belongs to. */
29
+ side: 'front' | 'back'
30
+ /** Heatmap intensity 0-1. */
31
+ intensity: number
32
+ /** Weekly-volume status relative to the landmarks. */
33
+ volumeStatus: VolumeStatus
34
+ /** Weekly effective sets logged. */
35
+ weeklySets: number
36
+ /** Volume landmarks (weekly working sets). */
37
+ landmarks: VolumeLandmarks
38
+ /** Last trained label, e.g. "2 days ago". */
39
+ lastTrained?: string
40
+ /** Weekly volume history for the panel sparkline. */
41
+ weeklyHistory?: number[]
42
+ /** Exercises contributing to this muscle's volume. */
43
+ contributingExercises?: ContributingExercise[]
44
+ /** Upcoming exercises targeting this muscle. */
45
+ upcomingExercises?: UpcomingExercise[]
46
+ }
47
+
48
+ /** Derived, page-level roll-up of the tracked muscles. */
49
+ export interface TrainingStatusSummary {
50
+ /** Total weekly effective sets across all tracked muscles. */
51
+ totalWeeklySets: number
52
+ /** Number of muscles being tracked. */
53
+ trackedMuscles: number
54
+ /** Count of muscles per volume status. */
55
+ statusCounts: Record<VolumeStatus, number>
56
+ }
57
+
58
+ export interface TrainingStatusPageProps extends ViewProps {
59
+ /** Page heading. */
60
+ title?: string
61
+ /** Mesocycle context banner shown at the top. */
62
+ meso: MesoStatusCardProps
63
+ /** Muscles tracked this week. */
64
+ muscles: TrainingStatusMuscle[]
65
+ className?: string
66
+ }
67
+
68
+ /** Roll up per-muscle rows into the page summary (pure, testable). */
69
+ export function deriveTrainingSummary(muscles: TrainingStatusMuscle[]): TrainingStatusSummary {
70
+ const statusCounts: Record<VolumeStatus, number> = {
71
+ under: 0,
72
+ maintenance: 0,
73
+ productive: 0,
74
+ over: 0,
75
+ }
76
+ let totalWeeklySets = 0
77
+ for (const muscle of muscles) {
78
+ totalWeeklySets += muscle.weeklySets
79
+ statusCounts[muscle.volumeStatus] += 1
80
+ }
81
+ return { totalWeeklySets, trackedMuscles: muscles.length, statusCounts }
82
+ }
83
+
84
+ /** Project the muscle rows for one side into `BodyMap` heatmap data. */
85
+ export function toBodyMapData(
86
+ muscles: TrainingStatusMuscle[],
87
+ side: 'front' | 'back'
88
+ ): BodyMapData[] {
89
+ return muscles
90
+ .filter((muscle) => muscle.side === side)
91
+ .map(({ muscleGroup, intensity, volumeStatus, weeklySets }) => ({
92
+ muscleGroup,
93
+ intensity,
94
+ volumeStatus,
95
+ weeklySets,
96
+ }))
97
+ }
98
+
99
+ const SUMMARY_CARDS: Array<{
100
+ key: keyof TrainingStatusSummary['statusCounts'] | 'total'
101
+ label: string
102
+ }> = [
103
+ { key: 'total', label: 'Weekly Sets' },
104
+ { key: 'productive', label: 'Productive' },
105
+ { key: 'under', label: 'Under' },
106
+ { key: 'over', label: 'Over' },
107
+ ]
108
+
109
+ function SummaryCards({ summary }: { summary: TrainingStatusSummary }) {
110
+ return (
111
+ <View className="flex-row flex-wrap" style={{ gap: 8 }} testID="training-status-page-summary">
112
+ {SUMMARY_CARDS.map(({ key, label }) => {
113
+ const value = key === 'total' ? summary.totalWeeklySets : summary.statusCounts[key]
114
+ return (
115
+ <View
116
+ key={key}
117
+ className="bg-surface-elevated border-border"
118
+ style={{
119
+ flexGrow: 1,
120
+ flexBasis: '46%',
121
+ padding: 12,
122
+ borderRadius: 10,
123
+ borderWidth: 1,
124
+ }}
125
+ testID={`training-status-page-summary-${key}`}
126
+ >
127
+ <Text
128
+ className="text-text-primary"
129
+ style={{
130
+ fontSize: 22,
131
+ fontFamily: '"Space Grotesk", sans-serif',
132
+ fontWeight: '700',
133
+ }}
134
+ >
135
+ {value}
136
+ </Text>
137
+ <Text
138
+ className="text-text-tertiary"
139
+ style={{
140
+ marginTop: 2,
141
+ fontSize: 11,
142
+ fontFamily: 'Inter, sans-serif',
143
+ fontWeight: '600',
144
+ letterSpacing: 0.4,
145
+ textTransform: 'uppercase',
146
+ }}
147
+ >
148
+ {label}
149
+ </Text>
150
+ </View>
151
+ )
152
+ })}
153
+ </View>
154
+ )
155
+ }
156
+
157
+ function StatusLegend() {
158
+ return (
159
+ <View
160
+ className="flex-row flex-wrap"
161
+ style={{ gap: 10, justifyContent: 'center' }}
162
+ testID="training-status-page-legend"
163
+ >
164
+ {STATUS_ORDER.map((status) => (
165
+ <View
166
+ key={status}
167
+ className="flex-row items-center"
168
+ style={{ gap: 5 }}
169
+ testID={`training-status-page-legend-${status}`}
170
+ >
171
+ <View
172
+ style={{
173
+ width: 8,
174
+ height: 8,
175
+ borderRadius: 9999,
176
+ backgroundColor: getHeatmapColor(status, 0.6),
177
+ }}
178
+ accessibilityElementsHidden
179
+ />
180
+ <Text
181
+ className="text-text-secondary"
182
+ style={{
183
+ fontSize: 11,
184
+ fontFamily: 'Inter, sans-serif',
185
+ textTransform: 'capitalize',
186
+ }}
187
+ >
188
+ {VOLUME_STATUS_LABELS[status]}
189
+ </Text>
190
+ </View>
191
+ ))}
192
+ </View>
193
+ )
194
+ }
195
+
196
+ interface BodyMapColumnProps {
197
+ side: 'front' | 'back'
198
+ muscles: TrainingStatusMuscle[]
199
+ selected: MuscleGroup | null
200
+ onSelect: (muscle: MuscleGroup) => void
201
+ }
202
+
203
+ function BodyMapColumn({ side, muscles, selected, onSelect }: BodyMapColumnProps) {
204
+ const data = useMemo(() => toBodyMapData(muscles, side), [muscles, side])
205
+ return (
206
+ <View style={{ flexGrow: 1, flexBasis: '46%' }} testID={`training-status-page-bodymap-${side}`}>
207
+ <BodyMap
208
+ data={data}
209
+ view={side}
210
+ onMusclePress={onSelect}
211
+ highlightedMuscle={selected}
212
+ mode="detailed"
213
+ />
214
+ </View>
215
+ )
216
+ }
217
+
218
+ /**
219
+ * TrainingStatusPage — a body-map training dashboard that composes the
220
+ * mesocycle context banner (`MesoStatusCard`), side-by-side front/back
221
+ * `BodyMap`s with a shared heatmap legend, per-status summary cards, and a
222
+ * tap-to-detail `BodyMapDetailPanel`. Tapping any muscle (SVG or legend chip)
223
+ * opens the slide-up panel for that group; the summary is derived from the
224
+ * supplied muscle rows.
225
+ *
226
+ * @example
227
+ * <TrainingStatusPage meso={meso} muscles={muscles} />
228
+ */
229
+ export function TrainingStatusPage({
230
+ title = 'Training Status',
231
+ meso,
232
+ muscles,
233
+ className,
234
+ ...props
235
+ }: TrainingStatusPageProps) {
236
+ const [selected, setSelected] = useState<MuscleGroup | null>(null)
237
+ const summary = useMemo(() => deriveTrainingSummary(muscles), [muscles])
238
+ const active = selected != null ? (muscles.find((m) => m.muscleGroup === selected) ?? null) : null
239
+
240
+ return (
241
+ <View
242
+ className={['bg-background-base', className].filter(Boolean).join(' ')}
243
+ style={{ position: 'relative', width: 390 }}
244
+ accessibilityRole={'main' as ViewProps['accessibilityRole']}
245
+ aria-label={title}
246
+ testID="training-status-page"
247
+ {...props}
248
+ >
249
+ <View style={{ padding: 16, gap: 16 }} testID="training-status-page-content">
250
+ <Text
251
+ accessibilityRole="header"
252
+ className="text-text-primary"
253
+ style={{
254
+ fontSize: 20,
255
+ fontFamily: '"Space Grotesk", sans-serif',
256
+ fontWeight: '700',
257
+ }}
258
+ testID="training-status-page-title"
259
+ >
260
+ {title}
261
+ </Text>
262
+
263
+ <MesoStatusCard {...meso} />
264
+
265
+ <SummaryCards summary={summary} />
266
+
267
+ <View
268
+ className="bg-surface-elevated border-border"
269
+ style={{
270
+ borderWidth: 1,
271
+ borderRadius: 12,
272
+ padding: 12,
273
+ gap: 12,
274
+ }}
275
+ testID="training-status-page-bodymaps"
276
+ >
277
+ <View className="flex-row" style={{ gap: 8 }}>
278
+ <BodyMapColumn
279
+ side="front"
280
+ muscles={muscles}
281
+ selected={selected}
282
+ onSelect={setSelected}
283
+ />
284
+ <BodyMapColumn
285
+ side="back"
286
+ muscles={muscles}
287
+ selected={selected}
288
+ onSelect={setSelected}
289
+ />
290
+ </View>
291
+ <StatusLegend />
292
+ </View>
293
+ </View>
294
+
295
+ {active != null && (
296
+ <BodyMapDetailPanel
297
+ muscleGroup={active.muscleGroup}
298
+ displayName={active.displayName}
299
+ weeklySets={active.weeklySets}
300
+ landmarks={active.landmarks}
301
+ volumeStatus={active.volumeStatus}
302
+ lastTrained={active.lastTrained}
303
+ weeklyHistory={active.weeklyHistory}
304
+ contributingExercises={active.contributingExercises}
305
+ upcomingExercises={active.upcomingExercises}
306
+ isOpen
307
+ onClose={() => setSelected(null)}
308
+ />
309
+ )}
310
+ </View>
311
+ )
312
+ }
@@ -232,3 +232,13 @@ describe('calculateMeanVelocity', () => {
232
232
  expect(calculateMeanVelocity([])).toBe(0)
233
233
  })
234
234
  })
235
+
236
+ describe('VelocityStrip all-zero velocities (NaN guard)', () => {
237
+ it('emits a valid 0% bar height (not NaN) when every velocity is zero (expanded)', () => {
238
+ render(<VelocityStrip velocities={[0, 0, 0]} expanded />)
239
+ // Without the guard, 0 / (0 * 1.15) === NaN and the bar height becomes
240
+ // 'NaN%' (dropped by jsdom, leaving no height); the guard flattens to '0%'.
241
+ expect(screen.getByTestId('velocity-bar-0')).toHaveStyle({ height: '0%' })
242
+ expect(screen.getByTestId('velocity-bar-2')).toHaveStyle({ height: '0%' })
243
+ })
244
+ })