Stabilize iOS/watchOS/tvOS apps and add cross-platform audit remediation
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
|
||||
import SwiftUI
|
||||
import HealthKit
|
||||
import SharedCore
|
||||
|
||||
struct CompletedWorkoutView: View {
|
||||
@ObservedObject var bridgeModule = BridgeModule.shared
|
||||
@@ -15,6 +16,9 @@ struct CompletedWorkoutView: View {
|
||||
@State var notes: String = ""
|
||||
@State var isUploading: Bool = false
|
||||
@State var gettingHealthKitData: Bool = false
|
||||
@State private var hasError = false
|
||||
@State private var errorMessage = ""
|
||||
private let runtimeReporter = RuntimeReporter.shared
|
||||
|
||||
var postData: [String: Any]
|
||||
let healthKitHelper = HealthKitHelper()
|
||||
@@ -60,7 +64,6 @@ struct CompletedWorkoutView: View {
|
||||
Spacer()
|
||||
|
||||
Button("Upload", action: {
|
||||
isUploading = true
|
||||
upload(postBody: postData)
|
||||
})
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
@@ -70,11 +73,14 @@ struct CompletedWorkoutView: View {
|
||||
.cornerRadius(Constants.buttonRadius)
|
||||
.padding()
|
||||
.frame(maxWidth: .infinity)
|
||||
.disabled(isUploading || gettingHealthKitData)
|
||||
}
|
||||
.padding([.leading, .trailing])
|
||||
}
|
||||
.onAppear{
|
||||
bridgeModule.sendWorkoutCompleteToWatch()
|
||||
.alert("Upload Failed", isPresented: $hasError) {
|
||||
Button("OK", role: .cancel) {}
|
||||
} message: {
|
||||
Text(errorMessage)
|
||||
}
|
||||
// .onChange(of: bridgeModule.healthKitUUID, perform: { healthKitUUID in
|
||||
// if let healthKitUUID = healthKitUUID {
|
||||
@@ -92,6 +98,11 @@ struct CompletedWorkoutView: View {
|
||||
}
|
||||
|
||||
func upload(postBody: [String: Any]) {
|
||||
guard isUploading == false else {
|
||||
return
|
||||
}
|
||||
isUploading = true
|
||||
|
||||
var _postBody = postBody
|
||||
_postBody["difficulty"] = difficulty
|
||||
_postBody["notes"] = notes
|
||||
@@ -103,6 +114,7 @@ struct CompletedWorkoutView: View {
|
||||
switch result {
|
||||
case .success(_):
|
||||
DispatchQueue.main.async {
|
||||
self.isUploading = false
|
||||
bridgeModule.resetCurrentWorkout()
|
||||
dismiss()
|
||||
completedWorkoutDismissed?(true)
|
||||
@@ -110,8 +122,13 @@ struct CompletedWorkoutView: View {
|
||||
case .failure(let failure):
|
||||
DispatchQueue.main.async {
|
||||
self.isUploading = false
|
||||
self.errorMessage = failure.localizedDescription
|
||||
self.hasError = true
|
||||
}
|
||||
print(failure)
|
||||
runtimeReporter.recordError(
|
||||
"Completed workout upload failed",
|
||||
metadata: ["error": failure.localizedDescription]
|
||||
)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user