@kingstinct/react-native-healthkit 10.1.0 → 11.0.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 (206) hide show
  1. package/ios/CoreModule.swift +5 -15
  2. package/ios/CorrelationTypeModule.swift +7 -2
  3. package/ios/QuantityTypeModule.swift +62 -110
  4. package/ios/Serializers.swift +39 -66
  5. package/ios/WorkoutProxy.swift +38 -20
  6. package/ios/WorkoutsModule.swift +7 -18
  7. package/lib/commonjs/hooks/useMostRecentWorkout.js +2 -9
  8. package/lib/commonjs/hooks/useWorkoutById.js +1 -4
  9. package/lib/commonjs/utils/getMostRecentWorkout.js +1 -3
  10. package/lib/commonjs/utils/getWorkoutById.js +1 -3
  11. package/lib/module/hooks/useMostRecentWorkout.js +3 -10
  12. package/lib/module/hooks/useWorkoutById.js +1 -4
  13. package/lib/module/utils/getMostRecentWorkout.js +1 -3
  14. package/lib/module/utils/getWorkoutById.js +1 -3
  15. package/lib/typescript/healthkit.d.ts +1 -1
  16. package/lib/typescript/healthkit.ios.d.ts +1 -1
  17. package/lib/typescript/hooks/useMostRecentWorkout.d.ts +1 -4
  18. package/lib/typescript/specs/WorkoutProxy.nitro.d.ts +11 -0
  19. package/lib/typescript/types/Workouts.d.ts +0 -8
  20. package/lib/typescript/utils/getMostRecentWorkout.d.ts +1 -2
  21. package/lib/typescript/utils/getWorkoutById.d.ts +1 -2
  22. package/nitrogen/generated/ios/ReactNativeHealthkit-Swift-Cxx-Bridge.cpp +103 -87
  23. package/nitrogen/generated/ios/ReactNativeHealthkit-Swift-Cxx-Bridge.hpp +748 -493
  24. package/nitrogen/generated/ios/ReactNativeHealthkitAutolinking.mm +8 -8
  25. package/nitrogen/generated/ios/ReactNativeHealthkitAutolinking.swift +16 -16
  26. package/nitrogen/generated/ios/c++/HybridCategoryTypeModuleSpecSwift.hpp +6 -4
  27. package/nitrogen/generated/ios/c++/HybridCharacteristicTypeModuleSpecSwift.hpp +4 -2
  28. package/nitrogen/generated/ios/c++/HybridCoreModuleSpecSwift.hpp +7 -5
  29. package/nitrogen/generated/ios/c++/HybridCorrelationTypeModuleSpecSwift.hpp +6 -4
  30. package/nitrogen/generated/ios/c++/HybridHeartbeatSeriesModuleSpecSwift.hpp +7 -5
  31. package/nitrogen/generated/ios/c++/HybridQuantityTypeModuleSpecSwift.hpp +5 -3
  32. package/nitrogen/generated/ios/c++/HybridSourceProxySpecSwift.hpp +3 -1
  33. package/nitrogen/generated/ios/c++/HybridStateOfMindModuleSpecSwift.hpp +7 -5
  34. package/nitrogen/generated/ios/c++/HybridWorkoutProxySpecSwift.hpp +50 -22
  35. package/nitrogen/generated/ios/c++/HybridWorkoutsModuleSpecSwift.hpp +9 -7
  36. package/nitrogen/generated/ios/swift/CategorySample.swift +4 -2
  37. package/nitrogen/generated/ios/swift/CategorySampleForSaving.swift +2 -1
  38. package/nitrogen/generated/ios/swift/CorrelationObject.swift +2 -0
  39. package/nitrogen/generated/ios/swift/DeletedSample.swift +2 -1
  40. package/nitrogen/generated/ios/swift/Device.swift +16 -8
  41. package/nitrogen/generated/ios/swift/FilterForSamples.swift +2 -0
  42. package/nitrogen/generated/ios/swift/Func_void_AuthorizationRequestStatus.swift +1 -0
  43. package/nitrogen/generated/ios/swift/Func_void_BiologicalSex.swift +1 -0
  44. package/nitrogen/generated/ios/swift/Func_void_BloodType.swift +1 -0
  45. package/nitrogen/generated/ios/swift/Func_void_CategorySamplesWithAnchorResponse.swift +1 -0
  46. package/nitrogen/generated/ios/swift/Func_void_FitzpatrickSkinType.swift +1 -0
  47. package/nitrogen/generated/ios/swift/Func_void_HeartbeatSeriesSamplesWithAnchorResponse.swift +1 -0
  48. package/nitrogen/generated/ios/swift/Func_void_OnChangeCallbackArgs.swift +1 -0
  49. package/nitrogen/generated/ios/swift/Func_void_QuantitySamplesWithAnchorResponse.swift +1 -0
  50. package/nitrogen/generated/ios/swift/Func_void_QueryStatisticsResponse.swift +1 -0
  51. package/nitrogen/generated/ios/swift/Func_void_QueryWorkoutSamplesWithAnchorResponse.swift +1 -0
  52. package/nitrogen/generated/ios/swift/Func_void_WheelchairUse.swift +1 -0
  53. package/nitrogen/generated/ios/swift/Func_void_bool.swift +1 -0
  54. package/nitrogen/generated/ios/swift/Func_void_double.swift +1 -0
  55. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +1 -0
  56. package/nitrogen/generated/ios/swift/Func_void_std__optional_QueryStatisticsResponse_.swift +54 -0
  57. package/nitrogen/generated/ios/swift/Func_void_std__optional_WorkoutPlan_.swift +3 -1
  58. package/nitrogen/generated/ios/swift/Func_void_std__optional_std__chrono__system_clock__time_point_.swift +3 -1
  59. package/nitrogen/generated/ios/swift/{Func_void_std__shared_ptr_margelo__nitro__healthkit__HybridWorkoutProxySpec_.swift → Func_void_std__shared_ptr_HybridWorkoutProxySpec_.swift} +9 -8
  60. package/nitrogen/generated/ios/swift/Func_void_std__unordered_map_std__string__QueryStatisticsResponse_.swift +55 -0
  61. package/nitrogen/generated/ios/swift/Func_void_std__unordered_map_std__string__bool_.swift +2 -1
  62. package/nitrogen/generated/ios/swift/Func_void_std__vector_CategorySample_.swift +1 -0
  63. package/nitrogen/generated/ios/swift/Func_void_std__vector_CorrelationSample_.swift +1 -0
  64. package/nitrogen/generated/ios/swift/Func_void_std__vector_HeartbeatSeriesSample_.swift +1 -0
  65. package/nitrogen/generated/ios/swift/Func_void_std__vector_IdentifierWithUnit_.swift +1 -0
  66. package/nitrogen/generated/ios/swift/Func_void_std__vector_QuantitySample_.swift +1 -0
  67. package/nitrogen/generated/ios/swift/Func_void_std__vector_QueryStatisticsResponse_.swift +1 -0
  68. package/nitrogen/generated/ios/swift/Func_void_std__vector_StateOfMindSample_.swift +1 -0
  69. package/nitrogen/generated/ios/swift/Func_void_std__vector_WorkoutRoute_.swift +1 -0
  70. package/nitrogen/generated/ios/swift/{Func_void_std__vector_std__shared_ptr_margelo__nitro__healthkit__HybridSourceProxySpec__.swift → Func_void_std__vector_std__shared_ptr_HybridSourceProxySpec__.swift} +9 -8
  71. package/nitrogen/generated/ios/swift/{Func_void_std__vector_std__shared_ptr_margelo__nitro__healthkit__HybridWorkoutProxySpec__.swift → Func_void_std__vector_std__shared_ptr_HybridWorkoutProxySpec__.swift} +9 -8
  72. package/nitrogen/generated/ios/swift/HeartbeatSeriesSample.swift +6 -3
  73. package/nitrogen/generated/ios/swift/HybridCategoryTypeModuleSpec.swift +2 -1
  74. package/nitrogen/generated/ios/swift/HybridCategoryTypeModuleSpec_cxx.swift +17 -7
  75. package/nitrogen/generated/ios/swift/HybridCharacteristicTypeModuleSpec.swift +2 -1
  76. package/nitrogen/generated/ios/swift/HybridCharacteristicTypeModuleSpec_cxx.swift +15 -6
  77. package/nitrogen/generated/ios/swift/HybridCoreModuleSpec.swift +2 -1
  78. package/nitrogen/generated/ios/swift/HybridCoreModuleSpec_cxx.swift +24 -15
  79. package/nitrogen/generated/ios/swift/HybridCorrelationTypeModuleSpec.swift +2 -1
  80. package/nitrogen/generated/ios/swift/HybridCorrelationTypeModuleSpec_cxx.swift +15 -6
  81. package/nitrogen/generated/ios/swift/HybridHeartbeatSeriesModuleSpec.swift +2 -1
  82. package/nitrogen/generated/ios/swift/HybridHeartbeatSeriesModuleSpec_cxx.swift +17 -7
  83. package/nitrogen/generated/ios/swift/HybridQuantityTypeModuleSpec.swift +2 -1
  84. package/nitrogen/generated/ios/swift/HybridQuantityTypeModuleSpec_cxx.swift +21 -9
  85. package/nitrogen/generated/ios/swift/HybridSourceProxySpec.swift +2 -1
  86. package/nitrogen/generated/ios/swift/HybridSourceProxySpec_cxx.swift +17 -7
  87. package/nitrogen/generated/ios/swift/HybridStateOfMindModuleSpec.swift +2 -1
  88. package/nitrogen/generated/ios/swift/HybridStateOfMindModuleSpec_cxx.swift +19 -8
  89. package/nitrogen/generated/ios/swift/HybridWorkoutProxySpec.swift +8 -5
  90. package/nitrogen/generated/ios/swift/HybridWorkoutProxySpec_cxx.swift +108 -41
  91. package/nitrogen/generated/ios/swift/HybridWorkoutsModuleSpec.swift +2 -1
  92. package/nitrogen/generated/ios/swift/HybridWorkoutsModuleSpec_cxx.swift +31 -22
  93. package/nitrogen/generated/ios/swift/OnChangeCallbackArgs.swift +2 -1
  94. package/nitrogen/generated/ios/swift/PredicateForSamples.swift +2 -0
  95. package/nitrogen/generated/ios/swift/PredicateForWorkouts.swift +2 -0
  96. package/nitrogen/generated/ios/swift/PredicateFromWorkout.swift +3 -3
  97. package/nitrogen/generated/ios/swift/PredicateWithMetadataKey.swift +2 -1
  98. package/nitrogen/generated/ios/swift/PredicateWithStartAndEnd.swift +4 -2
  99. package/nitrogen/generated/ios/swift/QuantitySample.swift +4 -2
  100. package/nitrogen/generated/ios/swift/QuantitySampleForSaving.swift +2 -1
  101. package/nitrogen/generated/ios/swift/QueryOptionsWithAnchor.swift +4 -2
  102. package/nitrogen/generated/ios/swift/QueryOptionsWithAnchorAndUnit.swift +6 -3
  103. package/nitrogen/generated/ios/swift/QueryOptionsWithSortOrder.swift +2 -1
  104. package/nitrogen/generated/ios/swift/QueryOptionsWithSortOrderAndUnit.swift +4 -2
  105. package/nitrogen/generated/ios/swift/QueryStatisticsResponse.swift +18 -9
  106. package/nitrogen/generated/ios/swift/QueryWorkoutSamplesWithAnchorResponse.swift +7 -7
  107. package/nitrogen/generated/ios/swift/SampleForSaving.swift +2 -0
  108. package/nitrogen/generated/ios/swift/SourceRevision.swift +13 -9
  109. package/nitrogen/generated/ios/swift/StateOfMindSample.swift +6 -3
  110. package/nitrogen/generated/ios/swift/StatisticsQueryOptions.swift +4 -2
  111. package/nitrogen/generated/ios/swift/Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout_FilterForSamplesAnd_FilterForSamplesOr.swift +2 -0
  112. package/nitrogen/generated/ios/swift/Variant_PredicateWithUUID_PredicateWithUUIDs_PredicateWithMetadataKey_PredicateWithStartAndEnd_PredicateFromWorkout_WorkoutActivityTypePredicate_WorkoutDurationPredicate_PredicateForWorkoutsOr_PredicateForWorkoutsAnd.swift +2 -0
  113. package/nitrogen/generated/ios/swift/Variant_String_Double_Bool_Date.swift +2 -0
  114. package/nitrogen/generated/ios/swift/WorkoutQueryOptions.swift +4 -61
  115. package/nitrogen/generated/ios/swift/WorkoutQueryOptionsWithAnchor.swift +6 -62
  116. package/nitrogen/generated/ios/swift/WorkoutRoute.swift +2 -1
  117. package/nitrogen/generated/ios/swift/WorkoutSample.swift +12 -123
  118. package/nitrogen/generated/shared/c++/AuthorizationRequestStatus.hpp +9 -11
  119. package/nitrogen/generated/shared/c++/AuthorizationStatus.hpp +9 -11
  120. package/nitrogen/generated/shared/c++/BiologicalSex.hpp +9 -11
  121. package/nitrogen/generated/shared/c++/BloodType.hpp +9 -11
  122. package/nitrogen/generated/shared/c++/CategorySample.hpp +14 -16
  123. package/nitrogen/generated/shared/c++/CategorySampleForSaving.hpp +11 -13
  124. package/nitrogen/generated/shared/c++/CategorySamplesWithAnchorResponse.hpp +11 -13
  125. package/nitrogen/generated/shared/c++/CategoryTypeIdentifier.hpp +131 -133
  126. package/nitrogen/generated/shared/c++/ComparisonPredicateOperator.hpp +26 -13
  127. package/nitrogen/generated/shared/c++/CorrelationSample.hpp +12 -14
  128. package/nitrogen/generated/shared/c++/CorrelationTypeIdentifier.hpp +7 -9
  129. package/nitrogen/generated/shared/c++/DeletedSample.hpp +5 -7
  130. package/nitrogen/generated/shared/c++/Device.hpp +5 -7
  131. package/nitrogen/generated/shared/c++/FilterForSamplesAnd.hpp +9 -11
  132. package/nitrogen/generated/shared/c++/FilterForSamplesOr.hpp +9 -11
  133. package/nitrogen/generated/shared/c++/FitzpatrickSkinType.hpp +9 -11
  134. package/nitrogen/generated/shared/c++/Heartbeat.hpp +4 -6
  135. package/nitrogen/generated/shared/c++/HeartbeatSeriesSample.hpp +15 -17
  136. package/nitrogen/generated/shared/c++/HeartbeatSeriesSamplesWithAnchorResponse.hpp +11 -13
  137. package/nitrogen/generated/shared/c++/HybridCategoryTypeModuleSpec.hpp +2 -2
  138. package/nitrogen/generated/shared/c++/HybridCharacteristicTypeModuleSpec.hpp +1 -1
  139. package/nitrogen/generated/shared/c++/HybridCoreModuleSpec.hpp +4 -4
  140. package/nitrogen/generated/shared/c++/HybridCorrelationTypeModuleSpec.hpp +2 -2
  141. package/nitrogen/generated/shared/c++/HybridHeartbeatSeriesModuleSpec.hpp +3 -3
  142. package/nitrogen/generated/shared/c++/HybridQuantityTypeModuleSpec.hpp +3 -3
  143. package/nitrogen/generated/shared/c++/HybridStateOfMindModuleSpec.hpp +3 -3
  144. package/nitrogen/generated/shared/c++/HybridWorkoutProxySpec.cpp +6 -4
  145. package/nitrogen/generated/shared/c++/HybridWorkoutProxySpec.hpp +18 -9
  146. package/nitrogen/generated/shared/c++/HybridWorkoutsModuleSpec.hpp +4 -4
  147. package/nitrogen/generated/shared/c++/IdentifierWithUnit.hpp +4 -6
  148. package/nitrogen/generated/shared/c++/IntervalComponents.hpp +4 -6
  149. package/nitrogen/generated/shared/c++/LocationForSaving.hpp +4 -6
  150. package/nitrogen/generated/shared/c++/ObjectTypeIdentifier.hpp +397 -399
  151. package/nitrogen/generated/shared/c++/OnChangeCallbackArgs.hpp +8 -10
  152. package/nitrogen/generated/shared/c++/PredicateForWorkoutsAnd.hpp +9 -11
  153. package/nitrogen/generated/shared/c++/PredicateForWorkoutsOr.hpp +9 -11
  154. package/nitrogen/generated/shared/c++/PredicateFromWorkout.hpp +6 -8
  155. package/nitrogen/generated/shared/c++/PredicateWithMetadataKey.hpp +9 -11
  156. package/nitrogen/generated/shared/c++/PredicateWithMetadataOperator.hpp +11 -13
  157. package/nitrogen/generated/shared/c++/PredicateWithStartAndEnd.hpp +5 -7
  158. package/nitrogen/generated/shared/c++/PredicateWithUUID.hpp +4 -6
  159. package/nitrogen/generated/shared/c++/PredicateWithUUIDs.hpp +5 -7
  160. package/nitrogen/generated/shared/c++/Quantity.hpp +4 -6
  161. package/nitrogen/generated/shared/c++/QuantityDateInterval.hpp +4 -6
  162. package/nitrogen/generated/shared/c++/QuantitySample.hpp +14 -16
  163. package/nitrogen/generated/shared/c++/QuantitySampleForSaving.hpp +11 -13
  164. package/nitrogen/generated/shared/c++/QuantitySamplesWithAnchorResponse.hpp +11 -13
  165. package/nitrogen/generated/shared/c++/QuantityTypeIdentifier.hpp +241 -243
  166. package/nitrogen/generated/shared/c++/QueryOptionsWithAnchor.hpp +9 -11
  167. package/nitrogen/generated/shared/c++/QueryOptionsWithAnchorAndUnit.hpp +9 -11
  168. package/nitrogen/generated/shared/c++/QueryOptionsWithSortOrder.hpp +8 -10
  169. package/nitrogen/generated/shared/c++/QueryOptionsWithSortOrderAndUnit.hpp +9 -11
  170. package/nitrogen/generated/shared/c++/QueryStatisticsResponse.hpp +26 -28
  171. package/nitrogen/generated/shared/c++/QueryWorkoutSamplesWithAnchorResponse.hpp +10 -12
  172. package/nitrogen/generated/shared/c++/SampleTypeIdentifier.hpp +383 -385
  173. package/nitrogen/generated/shared/c++/SampleTypeIdentifierWriteable.hpp +373 -375
  174. package/nitrogen/generated/shared/c++/Source.hpp +4 -6
  175. package/nitrogen/generated/shared/c++/SourceRevision.hpp +7 -9
  176. package/nitrogen/generated/shared/c++/StateOfMindAssociation.hpp +10 -12
  177. package/nitrogen/generated/shared/c++/StateOfMindKind.hpp +14 -13
  178. package/nitrogen/generated/shared/c++/StateOfMindLabel.hpp +10 -12
  179. package/nitrogen/generated/shared/c++/StateOfMindSample.hpp +24 -26
  180. package/nitrogen/generated/shared/c++/StateOfMindValenceClassification.hpp +10 -12
  181. package/nitrogen/generated/shared/c++/StatisticsOptions.hpp +17 -19
  182. package/nitrogen/generated/shared/c++/StatisticsQueryOptions.hpp +9 -11
  183. package/nitrogen/generated/shared/c++/UpdateFrequency.hpp +10 -12
  184. package/nitrogen/generated/shared/c++/WheelchairUse.hpp +9 -11
  185. package/nitrogen/generated/shared/c++/WorkoutActivity.hpp +4 -6
  186. package/nitrogen/generated/shared/c++/WorkoutActivityType.hpp +96 -13
  187. package/nitrogen/generated/shared/c++/WorkoutActivityTypePredicate.hpp +7 -9
  188. package/nitrogen/generated/shared/c++/WorkoutConfiguration.hpp +11 -13
  189. package/nitrogen/generated/shared/c++/WorkoutDurationPredicate.hpp +7 -9
  190. package/nitrogen/generated/shared/c++/WorkoutEvent.hpp +7 -9
  191. package/nitrogen/generated/shared/c++/WorkoutEventType.hpp +10 -12
  192. package/nitrogen/generated/shared/c++/WorkoutPlan.hpp +7 -9
  193. package/nitrogen/generated/shared/c++/WorkoutQueryOptions.hpp +10 -21
  194. package/nitrogen/generated/shared/c++/WorkoutQueryOptionsWithAnchor.hpp +11 -21
  195. package/nitrogen/generated/shared/c++/WorkoutRoute.hpp +9 -11
  196. package/nitrogen/generated/shared/c++/WorkoutRouteLocation.hpp +4 -6
  197. package/nitrogen/generated/shared/c++/WorkoutSample.hpp +25 -43
  198. package/nitrogen/generated/shared/c++/WorkoutSessionLocationType.hpp +10 -12
  199. package/nitrogen/generated/shared/c++/WorkoutTotals.hpp +4 -6
  200. package/package.json +11 -11
  201. package/src/hooks/useMostRecentWorkout.ts +3 -17
  202. package/src/hooks/useWorkoutById.ts +1 -4
  203. package/src/specs/WorkoutProxy.nitro.ts +18 -1
  204. package/src/types/Workouts.ts +0 -8
  205. package/src/utils/getMostRecentWorkout.ts +1 -6
  206. package/src/utils/getWorkoutById.ts +1 -6
@@ -304,25 +304,17 @@ class CoreModule: HybridCoreModuleSpec {
304
304
 
305
305
  let queryId = UUID().uuidString
306
306
 
307
- func responder(
308
- query: HKObserverQuery,
309
- handler: @escaping HKObserverQueryCompletionHandler,
310
- error: Error?
311
- ) {
312
- DispatchQueue.main.async {
313
- callback(OnChangeCallbackArgs(typeIdentifier: typeIdentifier, errorMessage: error?.localizedDescription))
314
- handler()
315
- }
316
- }
317
-
318
307
  let query = HKObserverQuery(
319
308
  sampleType: sampleType,
320
309
  predicate: predicate
321
310
  ) {
322
- (query: HKObserverQuery, handler: @escaping HKObserverQueryCompletionHandler, error: Error?)
311
+ (_: HKObserverQuery, handler: @escaping HKObserverQueryCompletionHandler, error: Error?)
323
312
  in
324
313
 
325
- return responder(query: query, handler: handler, error: error)
314
+ DispatchQueue.main.async {
315
+ callback(OnChangeCallbackArgs(typeIdentifier: typeIdentifier, errorMessage: error?.localizedDescription))
316
+ handler()
317
+ }
326
318
 
327
319
  }
328
320
 
@@ -330,8 +322,6 @@ class CoreModule: HybridCoreModuleSpec {
330
322
 
331
323
  self._runningQueries.updateValue(query, forKey: queryId)
332
324
 
333
- // resolve(queryId)
334
-
335
325
  return queryId
336
326
  }
337
327
 
@@ -14,7 +14,8 @@ class CorrelationTypeModule: HybridCorrelationTypeModuleSpec {
14
14
  var initializedSamples = Set<HKSample>()
15
15
 
16
16
  for sample in samples {
17
- if let quantitySample = sample as? QuantitySampleForSaving {
17
+ switch sample {
18
+ case .second(let quantitySample):
18
19
  let quantityTypeId = HKQuantityTypeIdentifier(rawValue: quantitySample.quantityType.stringValue)
19
20
  guard let quantityType = HKSampleType.quantityType(forIdentifier: quantityTypeId) else {
20
21
  continue
@@ -31,7 +32,7 @@ class CorrelationTypeModule: HybridCorrelationTypeModuleSpec {
31
32
  )
32
33
  initializedSamples.insert(hkQuantitySample)
33
34
 
34
- } else if let categorySample = sample as? CategorySampleForSaving {
35
+ case .first(let categorySample):
35
36
  let categoryType = try initializeCategoryType(categorySample.categoryType.stringValue)
36
37
 
37
38
  let hkCategorySample = HKCategorySample(
@@ -45,6 +46,10 @@ class CorrelationTypeModule: HybridCorrelationTypeModuleSpec {
45
46
  }
46
47
  }
47
48
 
49
+ if initializedSamples.isEmpty {
50
+ throw RuntimeError.error(withMessage: "[react-native-healthkit] No valid samples to create correlation sample")
51
+ }
52
+
48
53
  let correlation = HKCorrelation(
49
54
  type: correlationType,
50
55
  start: start,
@@ -49,6 +49,66 @@ func queryQuantitySamplesInternal(
49
49
 
50
50
  }
51
51
 
52
+ func serializeStatistics(gottenStats: HKStatistics, unit: HKUnit) -> QueryStatisticsResponse {
53
+ var response = QueryStatisticsResponse()
54
+
55
+ response.startDate = gottenStats.startDate
56
+ response.endDate = gottenStats.endDate
57
+
58
+ if let averageQuantity = gottenStats.averageQuantity() {
59
+ response.averageQuantity = Quantity(
60
+ unit: unit.unitString,
61
+ quantity: averageQuantity.doubleValue(for: unit)
62
+ )
63
+ }
64
+ if let maximumQuantity = gottenStats.maximumQuantity() {
65
+ response.maximumQuantity = Quantity(
66
+ unit: unit.unitString,
67
+ quantity: maximumQuantity.doubleValue(for: unit)
68
+ )
69
+ }
70
+ if let minimumQuantity = gottenStats.minimumQuantity() {
71
+ response.minimumQuantity = Quantity(
72
+ unit: unit.unitString,
73
+ quantity: minimumQuantity.doubleValue(for: unit)
74
+ )
75
+ }
76
+ if let sumQuantity = gottenStats.sumQuantity() {
77
+ response.sumQuantity = Quantity(
78
+ unit: unit.unitString,
79
+ quantity: sumQuantity.doubleValue(for: unit)
80
+ )
81
+ }
82
+
83
+ if #available(iOS 12, *) {
84
+ if let mostRecent = gottenStats.mostRecentQuantity() {
85
+ response.mostRecentQuantity = Quantity(
86
+ unit: unit.unitString,
87
+ quantity: mostRecent.doubleValue(for: unit)
88
+ )
89
+ }
90
+
91
+ if let mostRecentDateInterval = gottenStats.mostRecentQuantityDateInterval() {
92
+ response.mostRecentQuantityDateInterval = QuantityDateInterval(
93
+ from: mostRecentDateInterval.start,
94
+ to: mostRecentDateInterval.end
95
+ )
96
+ }
97
+ }
98
+
99
+ if #available(iOS 13, *) {
100
+ if let duration = gottenStats.duration() {
101
+ let durationUnit = HKUnit.second()
102
+ response.duration = Quantity(
103
+ unit: durationUnit.unitString,
104
+ quantity: duration.doubleValue(for: durationUnit)
105
+ )
106
+ }
107
+ }
108
+
109
+ return response
110
+ }
111
+
52
112
  func saveQuantitySampleInternal(
53
113
  typeIdentifier: HKQuantityType,
54
114
  unitString: String,
@@ -190,61 +250,7 @@ class QuantityTypeModule: HybridQuantityTypeModuleSpec {
190
250
  return
191
251
  }
192
252
 
193
- var response = QueryStatisticsResponse()
194
-
195
- response.startDate = gottenStats.startDate
196
- response.endDate = gottenStats.endDate
197
-
198
- if let averageQuantity = gottenStats.averageQuantity() {
199
- response.averageQuantity = Quantity(
200
- unit: unit.unitString,
201
- quantity: averageQuantity.doubleValue(for: unit)
202
- )
203
- }
204
- if let maximumQuantity = gottenStats.maximumQuantity() {
205
- response.maximumQuantity = Quantity(
206
- unit: unit.unitString,
207
- quantity: maximumQuantity.doubleValue(for: unit)
208
- )
209
- }
210
- if let minimumQuantity = gottenStats.minimumQuantity() {
211
- response.minimumQuantity = Quantity(
212
- unit: unit.unitString,
213
- quantity: minimumQuantity.doubleValue(for: unit)
214
- )
215
- }
216
- if let sumQuantity = gottenStats.sumQuantity() {
217
- response.sumQuantity = Quantity(
218
- unit: unit.unitString,
219
- quantity: sumQuantity.doubleValue(for: unit)
220
- )
221
- }
222
-
223
- if #available(iOS 12, *) {
224
- if let mostRecent = gottenStats.mostRecentQuantity() {
225
- response.mostRecentQuantity = Quantity(
226
- unit: unit.unitString,
227
- quantity: mostRecent.doubleValue(for: unit)
228
- )
229
- }
230
-
231
- if let mostRecentDateInterval = gottenStats.mostRecentQuantityDateInterval() {
232
- response.mostRecentQuantityDateInterval = QuantityDateInterval(
233
- from: mostRecentDateInterval.start,
234
- to: mostRecentDateInterval.end
235
- )
236
- }
237
- }
238
-
239
- if #available(iOS 13, *) {
240
- if let duration = gottenStats.duration() {
241
- let durationUnit = HKUnit.second()
242
- response.duration = Quantity(
243
- unit: durationUnit.unitString,
244
- quantity: duration.doubleValue(for: durationUnit)
245
- )
246
- }
247
- }
253
+ var response = serializeStatistics(gottenStats: gottenStats, unit: unit)
248
254
 
249
255
  continuation.resume(returning: response)
250
256
  }
@@ -326,61 +332,7 @@ class QuantityTypeModule: HybridQuantityTypeModuleSpec {
326
332
  }
327
333
 
328
334
  statistics.enumerateStatistics(from: enumerateFrom, to: enumerateTo) { stats, _ in
329
- var response = QueryStatisticsResponse()
330
-
331
- response.startDate = stats.startDate
332
- response.endDate = stats.endDate
333
-
334
- if let averageQuantity = stats.averageQuantity() {
335
- response.averageQuantity = Quantity(
336
- unit: unit.unitString,
337
- quantity: averageQuantity.doubleValue(for: unit)
338
- )
339
- }
340
- if let maximumQuantity = stats.maximumQuantity() {
341
- response.maximumQuantity = Quantity(
342
- unit: unit.unitString,
343
- quantity: maximumQuantity.doubleValue(for: unit)
344
- )
345
- }
346
- if let minimumQuantity = stats.minimumQuantity() {
347
- response.minimumQuantity = Quantity(
348
- unit: unit.unitString,
349
- quantity: minimumQuantity.doubleValue(for: unit)
350
- )
351
- }
352
- if let sumQuantity = stats.sumQuantity() {
353
- response.sumQuantity = Quantity(
354
- unit: unit.unitString,
355
- quantity: sumQuantity.doubleValue(for: unit)
356
- )
357
- }
358
-
359
- if #available(iOS 12, *) {
360
- if let mostRecent = stats.mostRecentQuantity() {
361
- response.mostRecentQuantity = Quantity(
362
- unit: unit.unitString,
363
- quantity: mostRecent.doubleValue(for: unit)
364
- )
365
- }
366
-
367
- if let mostRecentDateInterval = stats.mostRecentQuantityDateInterval() {
368
- response.mostRecentQuantityDateInterval = QuantityDateInterval(
369
- from: mostRecentDateInterval.start,
370
- to: mostRecentDateInterval.end
371
- )
372
- }
373
- }
374
-
375
- if #available(iOS 13, *) {
376
- if let duration = stats.duration() {
377
- let durationUnit = HKUnit.second()
378
- response.duration = Quantity(
379
- unit: durationUnit.unitString,
380
- quantity: duration.doubleValue(for: durationUnit)
381
- )
382
- }
383
- }
335
+ var response = serializeStatistics(gottenStats: stats, unit: unit)
384
336
 
385
337
  responseArray.append(response)
386
338
  }
@@ -70,90 +70,61 @@ func serializeSource(_ source: HKSource) -> SourceProxy {
70
70
  )
71
71
  }
72
72
 
73
- func getUnitForQuantityType(quantityType: HKQuantityType) -> HKUnit? {
74
- if quantityType.is(compatibleWith: HKUnit.percent()) {
75
- return HKUnit.percent()
73
+ func serializeUnknownQuantityTyped(quantity: HKQuantity?) -> Quantity? {
74
+ guard let quantity = quantity else {
75
+ return nil
76
76
  }
77
77
 
78
- if quantityType.is(compatibleWith: HKUnit.second()) {
79
- return HKUnit.second()
78
+ if quantity.is(compatibleWith: HKUnit.percent()) {
79
+ return serializeQuantityTyped(unit: HKUnit.percent(), quantity: quantity)
80
80
  }
81
81
 
82
- if quantityType.is(compatibleWith: HKUnit.kilocalorie()) {
83
- return HKUnit.kilocalorie()
82
+ if quantity.is(compatibleWith: HKUnit.second()) {
83
+ return serializeQuantityTyped(unit: HKUnit.second(), quantity: quantity)
84
84
  }
85
85
 
86
- if quantityType.is(compatibleWith: HKUnit.count()) {
87
- return HKUnit.count()
86
+ if quantity.is(compatibleWith: HKUnit.kilocalorie()) {
87
+ return serializeQuantityTyped(unit: HKUnit.kilocalorie(), quantity: quantity)
88
88
  }
89
89
 
90
- if quantityType.is(compatibleWith: HKUnit.meter()) {
91
- return HKUnit.meter()
90
+ if quantity.is(compatibleWith: HKUnit.count()) {
91
+ return serializeQuantityTyped(unit: HKUnit.count(), quantity: quantity)
92
92
  }
93
93
 
94
- if quantityType.is(compatibleWith: SpeedUnit) {
95
- return SpeedUnit
94
+ if quantity.is(compatibleWith: HKUnit.meter()) {
95
+ return serializeQuantityTyped(unit: HKUnit.meter(), quantity: quantity)
96
96
  }
97
97
 
98
- if quantityType.is(compatibleWith: METUnit) {
99
- return METUnit
98
+ if quantity.is(compatibleWith: HKUnit.degreeCelsius()) {
99
+ return serializeQuantityTyped(unit: HKUnit.degreeCelsius(), quantity: quantity)
100
100
  }
101
101
 
102
- if #available(iOS 11, *) {
103
- if quantityType.is(compatibleWith: HKUnit.internationalUnit()) {
104
- return HKUnit.internationalUnit()
105
- }
102
+ if quantity.is(compatibleWith: HKUnit.atmosphere()) {
103
+ return serializeQuantityTyped(unit: HKUnit.atmosphere(), quantity: quantity)
106
104
  }
107
105
 
108
- if #available(iOS 13, *) {
109
- if quantityType.is(compatibleWith: HKUnit.hertz()) {
110
- return HKUnit.hertz()
111
- }
112
- if quantityType.is(compatibleWith: HKUnit.decibelHearingLevel()) {
113
- return HKUnit.decibelHearingLevel()
114
- }
106
+ if quantity.is(compatibleWith: HKUnit.gram()) {
107
+ return serializeQuantityTyped(unit: HKUnit.gram(), quantity: quantity)
115
108
  }
116
109
 
117
- if #available(iOS 17.0, *) {
118
- if quantityType.is(compatibleWith: HKUnit.lux()) {
119
- return HKUnit.lux()
120
- }
110
+ if quantity.is(compatibleWith: HKUnit.liter()) {
111
+ return serializeQuantityTyped(unit: HKUnit.liter(), quantity: quantity)
121
112
  }
122
113
 
123
- #if compiler(>=6)
124
- if #available(iOS 18.0, *) {
125
- if quantityType.is(compatibleWith: HKUnit.appleEffortScore()) {
126
- return HKUnit.appleEffortScore()
127
- }
114
+ if quantity.is(compatibleWith: HKUnit.volt()) {
115
+ return serializeQuantityTyped(unit: HKUnit.volt(), quantity: quantity)
128
116
  }
129
- #endif
130
117
 
131
- return nil
132
- }
133
-
134
- func serializeUnknownQuantityTyped(quantity: HKQuantity?) -> Quantity? {
135
- guard let quantity = quantity else {
136
- return nil
118
+ if quantity.is(compatibleWith: HKUnit.hertz()) {
119
+ return serializeQuantityTyped(unit: HKUnit.hertz(), quantity: quantity)
137
120
  }
138
121
 
139
- if quantity.is(compatibleWith: HKUnit.percent()) {
140
- return serializeQuantityTyped(unit: HKUnit.percent(), quantity: quantity)
141
- }
142
-
143
- if quantity.is(compatibleWith: HKUnit.second()) {
144
- return serializeQuantityTyped(unit: HKUnit.second(), quantity: quantity)
145
- }
146
-
147
- if quantity.is(compatibleWith: HKUnit.kilocalorie()) {
148
- return serializeQuantityTyped(unit: HKUnit.kilocalorie(), quantity: quantity)
149
- }
150
-
151
- if quantity.is(compatibleWith: HKUnit.count()) {
152
- return serializeQuantityTyped(unit: HKUnit.count(), quantity: quantity)
122
+ if quantity.is(compatibleWith: SpeedUnit) {
123
+ return serializeQuantityTyped(unit: SpeedUnit, quantity: quantity)
153
124
  }
154
125
 
155
- if quantity.is(compatibleWith: HKUnit.meter()) {
156
- return serializeQuantityTyped(unit: HKUnit.meter(), quantity: quantity)
126
+ if quantity.is(compatibleWith: METUnit) {
127
+ return serializeQuantityTyped(unit: METUnit, quantity: quantity)
157
128
  }
158
129
 
159
130
  if #available(iOS 11, *) {
@@ -171,6 +142,16 @@ func serializeUnknownQuantityTyped(quantity: HKQuantity?) -> Quantity? {
171
142
  }
172
143
  }
173
144
 
145
+ if #available(iOS 16.0, *) {
146
+ if quantity.is(compatibleWith: HKUnit.watt()) {
147
+ return serializeQuantityTyped(unit: HKUnit.watt(), quantity: quantity)
148
+ }
149
+
150
+ if quantity.is(compatibleWith: HKUnit.degreeAngle()) {
151
+ return serializeQuantityTyped(unit: HKUnit.degreeAngle(), quantity: quantity)
152
+ }
153
+ }
154
+
174
155
  if #available(iOS 17.0, *) {
175
156
  if quantity.is(compatibleWith: HKUnit.lux()) {
176
157
  return serializeQuantityTyped(unit: HKUnit.lux(), quantity: quantity)
@@ -185,14 +166,6 @@ func serializeUnknownQuantityTyped(quantity: HKQuantity?) -> Quantity? {
185
166
  }
186
167
  #endif
187
168
 
188
- if quantity.is(compatibleWith: SpeedUnit) {
189
- return serializeQuantityTyped(unit: SpeedUnit, quantity: quantity)
190
- }
191
-
192
- if quantity.is(compatibleWith: METUnit) {
193
- return serializeQuantityTyped(unit: METUnit, quantity: quantity)
194
- }
195
-
196
169
  return nil
197
170
  }
198
171
 
@@ -149,17 +149,16 @@ func getSerializedWorkoutLocations(
149
149
  previousLocation: i == 0 ? nil : routeCLLocations[i - 1]
150
150
  )
151
151
  }
152
- // let routeInfos: WorkoutRoute = ["locations": routeLocations]
153
152
 
154
153
  allRoutes.append(
155
154
  WorkoutRoute(
156
155
  locations: routeLocations,
157
- HKMetadataKeySyncIdentifier: routeMetadata.getString(
156
+ HKMetadataKeySyncIdentifier: routeMetadata.isString(key: "HKMetadataKeySyncIdentifier") ? routeMetadata.getString(
158
157
  key: "HKMetadataKeySyncIdentifier"
159
- ),
160
- HKMetadataKeySyncVersion: routeMetadata.getDouble(
158
+ ) : nil,
159
+ HKMetadataKeySyncVersion: routeMetadata.isDouble(key: "HKMetadataKeySyncVersion") ? routeMetadata.getDouble(
161
160
  key: "HKMetadataKeySyncVersion"
162
- )
161
+ ) : nil
163
162
  )
164
163
  )
165
164
  }
@@ -194,9 +193,39 @@ func saveWorkoutRouteInternal(
194
193
  }
195
194
 
196
195
  class WorkoutProxy: HybridWorkoutProxySpec {
196
+
197
+ // Return a Promise instead of directly returning the value; wrap async logic.
198
+ func getStatistic(quantityType: QuantityTypeIdentifier, unitOverride: String?) throws -> Promise<QueryStatisticsResponse?> {
199
+ return Promise.async {
200
+ if #available(iOS 16.0, *) {
201
+ let type = try initializeQuantityType(quantityType.stringValue)
202
+ if let stats = self.workout.statistics(for: type) {
203
+ let unit = try await getUnitToUse(unitOverride: unitOverride, quantityType: type)
204
+ return serializeStatistics(gottenStats: stats, unit: unit)
205
+ }
206
+ }
207
+ return nil
208
+ }
209
+ }
210
+
211
+ func getAllStatistics() throws -> Promise<[String: QueryStatisticsResponse]> {
212
+ return Promise.async {
213
+ var result: [String: QueryStatisticsResponse] = [:]
214
+ if #available(iOS 16.0, *) {
215
+ let statsMap = self.workout.allStatistics
216
+ for (quantityType, stats) in statsMap {
217
+ let unit = try await getUnitToUse(unitOverride: nil, quantityType: quantityType)
218
+ let serialized = serializeStatistics(gottenStats: stats, unit: unit)
219
+ result[quantityType.identifier] = serialized
220
+ }
221
+ }
222
+ return result
223
+ }
224
+ }
225
+
197
226
  func toJSON(key: String?) throws -> WorkoutSample {
198
- if key != nil && key?.isEmpty != true {
199
- print("WorkoutProxy does not support toJSON with key: \(key!)")
227
+ if let key = key, !key.isEmpty {
228
+ print("WorkoutProxy does not support toJSON with key: \(key)")
200
229
  }
201
230
 
202
231
  return WorkoutSample(
@@ -204,10 +233,6 @@ class WorkoutProxy: HybridWorkoutProxySpec {
204
233
  device: self.device,
205
234
  workoutActivityType: self.workoutActivityType,
206
235
  duration: self.duration,
207
- totalDistance: self.totalDistance,
208
- totalEnergyBurned: self.totalEnergyBurned,
209
- totalSwimmingStrokeCount: self.totalSwimmingStrokeCount,
210
- totalFlightsClimbed: self.totalFlightsClimbed,
211
236
  startDate: self.startDate,
212
237
  endDate: self.endDate,
213
238
  metadata: self.metadata,
@@ -286,7 +311,7 @@ class WorkoutProxy: HybridWorkoutProxySpec {
286
311
  var totalEnergyBurned: Quantity? {
287
312
  get {
288
313
  return serializeQuantityTyped(
289
- unit: energyUnit,
314
+ unit: HKUnit.kilocalorie(),
290
315
  quantityNullable: workout.totalEnergyBurned
291
316
  )
292
317
  }
@@ -314,8 +339,6 @@ class WorkoutProxy: HybridWorkoutProxySpec {
314
339
  return nil
315
340
  }
316
341
 
317
- var energyUnit: HKUnit
318
-
319
342
  var startDate: Date {
320
343
  get {
321
344
  return workout.startDate
@@ -377,14 +400,9 @@ class WorkoutProxy: HybridWorkoutProxySpec {
377
400
  return nil
378
401
  }
379
402
 
380
- let distanceUnit: HKUnit
381
-
382
403
  private let workout: HKWorkout
383
404
 
384
- init(workout: HKWorkout, distanceUnit: HKUnit, energyUnit: HKUnit) {
385
- self.energyUnit = energyUnit
386
- self.distanceUnit = distanceUnit
387
-
405
+ init(workout: HKWorkout) {
388
406
  self.workout = workout
389
407
  }
390
408
 
@@ -57,10 +57,6 @@ class WorkoutsModule: HybridWorkoutsModuleSpec {
57
57
  let limit = getQueryLimit(options.limit)
58
58
 
59
59
  return Promise.async {
60
- let energyUnit = try await getUnitToUse(unitOverride: options.energyUnit, quantityType: HKQuantityType(.activeEnergyBurned))
61
-
62
- let distanceUnit = try await getUnitToUse(unitOverride: options.distanceUnit, quantityType: HKQuantityType(.distanceWalkingRunning))
63
-
64
60
  return try await withCheckedThrowingContinuation { continuation in
65
61
  let q = HKSampleQuery(
66
62
  sampleType: .workoutType(),
@@ -79,9 +75,7 @@ class WorkoutsModule: HybridWorkoutsModuleSpec {
79
75
  let workoutProxies = samples.compactMap { s in
80
76
  if let workout = s as? HKWorkout {
81
77
  return WorkoutProxy.init(
82
- workout: workout,
83
- distanceUnit: distanceUnit,
84
- energyUnit: energyUnit
78
+ workout: workout
85
79
  )
86
80
  }
87
81
  return nil
@@ -221,9 +215,11 @@ class WorkoutsModule: HybridWorkoutsModuleSpec {
221
215
  if let error = error {
222
216
  return continuation.resume(throwing: error)
223
217
  }
224
- store.add(initializedSamples, to: workout) { (_, error: Error?) in
225
- if let error = error {
226
- return continuation.resume(throwing: error)
218
+ if !initializedSamples.isEmpty {
219
+ store.add(initializedSamples, to: workout) { (_, error: Error?) in
220
+ if let error = error {
221
+ return continuation.resume(throwing: error)
222
+ }
227
223
  }
228
224
  }
229
225
  return continuation.resume()
@@ -231,9 +227,7 @@ class WorkoutsModule: HybridWorkoutsModuleSpec {
231
227
  }) as Void
232
228
 
233
229
  return WorkoutProxy.init(
234
- workout: workout,
235
- distanceUnit: .meter(),
236
- energyUnit: .kilocalorie()
230
+ workout: workout
237
231
  )
238
232
  }
239
233
  }
@@ -246,9 +240,6 @@ class WorkoutsModule: HybridWorkoutsModuleSpec {
246
240
  let actualAnchor = try deserializeHKQueryAnchor(base64String: options.anchor)
247
241
 
248
242
  return Promise.async {
249
- let energyUnit = try await getUnitToUse(unitOverride: options.energyUnit, quantityType: HKQuantityType(.activeEnergyBurned))
250
-
251
- let distanceUnit = try await getUnitToUse(unitOverride: options.energyUnit, quantityType: HKQuantityType(.distanceWalkingRunning))
252
243
 
253
244
  return try await withCheckedThrowingContinuation { continuation in
254
245
  let q = HKAnchoredObjectQuery(
@@ -280,8 +271,6 @@ class WorkoutsModule: HybridWorkoutsModuleSpec {
280
271
  if let workout = s as? HKWorkout {
281
272
  return WorkoutProxy.init(
282
273
  workout: workout,
283
- distanceUnit: distanceUnit,
284
- energyUnit: energyUnit
285
274
  )
286
275
  }
287
276
  return nil
@@ -10,17 +10,10 @@ const useSubscribeToChanges_1 = __importDefault(require("./useSubscribeToChanges
10
10
  /**
11
11
  * @returns the most recent workout sample.
12
12
  */
13
- function useMostRecentWorkout(options) {
13
+ function useMostRecentWorkout() {
14
14
  const [workout, setWorkout] = (0, react_1.useState)();
15
- const optionsRef = (0, react_1.useRef)(options);
16
- (0, react_1.useEffect)(() => {
17
- optionsRef.current = options;
18
- }, [options]);
19
15
  const update = (0, react_1.useCallback)(async () => {
20
- setWorkout(await (0, getMostRecentWorkout_1.default)({
21
- energyUnit: optionsRef.current?.energyUnit,
22
- distanceUnit: optionsRef.current?.distanceUnit,
23
- }));
16
+ setWorkout(await (0, getMostRecentWorkout_1.default)());
24
17
  }, []);
25
18
  (0, react_1.useEffect)(() => {
26
19
  void update();
@@ -22,10 +22,7 @@ function useWorkoutById(uuid, options) {
22
22
  setIsLoading(true);
23
23
  setError(null);
24
24
  try {
25
- const fetchedWorkout = await (0, getWorkoutById_1.default)(uuid, {
26
- energyUnit: optionsRef.current?.energyUnit,
27
- distanceUnit: optionsRef.current?.distanceUnit,
28
- });
25
+ const fetchedWorkout = await (0, getWorkoutById_1.default)(uuid);
29
26
  setWorkout(fetchedWorkout);
30
27
  }
31
28
  catch (err) {
@@ -1,12 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const modules_1 = require("../modules");
4
- const getMostRecentWorkout = async (options) => {
4
+ const getMostRecentWorkout = async () => {
5
5
  const workouts = await modules_1.Workouts.queryWorkoutSamples({
6
6
  limit: 1,
7
7
  ascending: false,
8
- energyUnit: options?.energyUnit,
9
- distanceUnit: options?.distanceUnit,
10
8
  });
11
9
  return workouts[0];
12
10
  };
@@ -1,14 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const modules_1 = require("../modules");
4
- const getWorkoutById = async (uuid, options) => {
4
+ const getWorkoutById = async (uuid) => {
5
5
  const workouts = await modules_1.Workouts.queryWorkoutSamples({
6
6
  limit: 1,
7
7
  filter: {
8
8
  uuid: uuid,
9
9
  },
10
- energyUnit: options?.energyUnit,
11
- distanceUnit: options?.distanceUnit,
12
10
  });
13
11
  return workouts[0];
14
12
  };
@@ -1,20 +1,13 @@
1
- import { useCallback, useEffect, useRef, useState } from 'react';
1
+ import { useCallback, useEffect, useState } from 'react';
2
2
  import getMostRecentWorkout from '../utils/getMostRecentWorkout';
3
3
  import useSubscribeToChanges from './useSubscribeToChanges';
4
4
  /**
5
5
  * @returns the most recent workout sample.
6
6
  */
7
- export function useMostRecentWorkout(options) {
7
+ export function useMostRecentWorkout() {
8
8
  const [workout, setWorkout] = useState();
9
- const optionsRef = useRef(options);
10
- useEffect(() => {
11
- optionsRef.current = options;
12
- }, [options]);
13
9
  const update = useCallback(async () => {
14
- setWorkout(await getMostRecentWorkout({
15
- energyUnit: optionsRef.current?.energyUnit,
16
- distanceUnit: optionsRef.current?.distanceUnit,
17
- }));
10
+ setWorkout(await getMostRecentWorkout());
18
11
  }, []);
19
12
  useEffect(() => {
20
13
  void update();