|
3 | 3 | */ |
4 | 4 |
|
5 | 5 | import { useMemo } from 'react'; |
6 | | -import { useWorkouts } from './useWorkouts'; |
| 6 | +import { useWorkouts, type ViewMode } from './useWorkouts'; |
7 | 7 | import { useProfile } from './useProfiles'; |
8 | 8 | import { useExerciseMappings } from './useExerciseMappings'; |
9 | 9 | import { calculateMuscleVolume, aggregateToFunctionalGroups } from '@core/volume-calculator'; |
@@ -110,19 +110,27 @@ function convertSets(dbSets: WorkoutSet[]): WorkoutSet[] { |
110 | 110 | return dbSets; |
111 | 111 | } |
112 | 112 |
|
| 113 | +export type { ViewMode }; |
| 114 | + |
113 | 115 | /** |
114 | 116 | * Get volume statistics at the ScientificMuscle level |
| 117 | + * @param profileId - Profile ID |
| 118 | + * @param daysBackOrMode - Number of days back (legacy) or ViewMode ('last7days' | 'calendarWeek') |
115 | 119 | */ |
116 | 120 | export function useScientificMuscleVolume( |
117 | 121 | profileId: string | null, |
118 | | - daysBack: number = 7 |
| 122 | + daysBackOrMode: number | ViewMode = 7 |
119 | 123 | ): { |
120 | 124 | stats: VolumeStatItem[]; |
121 | 125 | totalVolume: number; |
122 | 126 | isLoading: boolean; |
123 | 127 | error: Error | null; |
124 | 128 | } { |
125 | | - const { workouts, isLoading: workoutsLoading, error } = useWorkouts(profileId, daysBack); |
| 129 | + // Convert to options format for useWorkouts |
| 130 | + const workoutsArg = typeof daysBackOrMode === 'number' |
| 131 | + ? daysBackOrMode |
| 132 | + : { mode: daysBackOrMode }; |
| 133 | + const { workouts, isLoading: workoutsLoading, error } = useWorkouts(profileId, workoutsArg); |
126 | 134 | const { profile } = useProfile(profileId); |
127 | 135 | const { mappings: userMappings, isLoading: mappingsLoading } = useExerciseMappings(profileId); |
128 | 136 |
|
@@ -161,18 +169,24 @@ export function useScientificMuscleVolume( |
161 | 169 |
|
162 | 170 | /** |
163 | 171 | * Get volume statistics at the FunctionalGroup level |
| 172 | + * @param profileId - Profile ID |
| 173 | + * @param daysBackOrMode - Number of days back (legacy) or ViewMode ('last7days' | 'calendarWeek') |
164 | 174 | */ |
165 | 175 | export function useFunctionalGroupVolume( |
166 | 176 | profileId: string | null, |
167 | | - daysBack: number = 7 |
| 177 | + daysBackOrMode: number | ViewMode = 7 |
168 | 178 | ): { |
169 | 179 | stats: VolumeStatItem[]; |
170 | 180 | totalVolume: number; |
171 | 181 | totalGoal: number; |
172 | 182 | isLoading: boolean; |
173 | 183 | error: Error | null; |
174 | 184 | } { |
175 | | - const { workouts, isLoading: workoutsLoading, error } = useWorkouts(profileId, daysBack); |
| 185 | + // Convert to options format for useWorkouts |
| 186 | + const workoutsArg = typeof daysBackOrMode === 'number' |
| 187 | + ? daysBackOrMode |
| 188 | + : { mode: daysBackOrMode }; |
| 189 | + const { workouts, isLoading: workoutsLoading, error } = useWorkouts(profileId, workoutsArg); |
176 | 190 | const { profile } = useProfile(profileId); |
177 | 191 | const { mappings: userMappings, isLoading: mappingsLoading } = useExerciseMappings(profileId); |
178 | 192 |
|
@@ -232,17 +246,20 @@ export function useFunctionalGroupVolume( |
232 | 246 |
|
233 | 247 | /** |
234 | 248 | * Get the breakdown of scientific muscles within a functional group |
| 249 | + * @param profileId - Profile ID |
| 250 | + * @param functionalGroup - Functional group to get breakdown for |
| 251 | + * @param daysBackOrMode - Number of days back (legacy) or ViewMode ('last7days' | 'calendarWeek') |
235 | 252 | */ |
236 | 253 | export function useFunctionalGroupBreakdown( |
237 | 254 | profileId: string | null, |
238 | 255 | functionalGroup: FunctionalGroup, |
239 | | - daysBack: number = 7 |
| 256 | + daysBackOrMode: number | ViewMode = 7 |
240 | 257 | ): { |
241 | 258 | breakdown: VolumeStatItem[]; |
242 | 259 | isLoading: boolean; |
243 | 260 | error: Error | null; |
244 | 261 | } { |
245 | | - const { stats, isLoading, error } = useScientificMuscleVolume(profileId, daysBack); |
| 262 | + const { stats, isLoading, error } = useScientificMuscleVolume(profileId, daysBackOrMode); |
246 | 263 | const { profile } = useProfile(profileId); |
247 | 264 |
|
248 | 265 | const breakdown = useMemo(() => { |
|
0 commit comments