104 lines
2.8 KiB
Swift
104 lines
2.8 KiB
Swift
//
|
|
// CompletedWorkoutView.swift
|
|
// Werkout_ios
|
|
//
|
|
// Created by Trey Tartt on 6/22/23.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct CompletedWorkoutView: View {
|
|
@ObservedObject var bridgeModule = BridgeModule.shared
|
|
var postData: [String: Any]
|
|
let workout: Workout
|
|
@Environment(\.dismiss) var dismiss
|
|
|
|
@State var difficulty: Float = 0
|
|
@State var notes: String = ""
|
|
let completedWorkoutDismissed: ((Bool) -> Void)?
|
|
|
|
var body: some View {
|
|
VStack {
|
|
Text(workout.name)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
.font(.title3)
|
|
.padding(.top
|
|
)
|
|
if let desc = workout.description {
|
|
Text(desc)
|
|
.frame(maxWidth: .infinity, alignment: .leading)
|
|
.font(.body)
|
|
.padding(.top)
|
|
|
|
}
|
|
|
|
Divider()
|
|
|
|
Text("how hard was this shit")
|
|
|
|
HStack {
|
|
Text("easy")
|
|
Spacer()
|
|
Text("Death")
|
|
}
|
|
|
|
Slider(value: $difficulty, in: 0...5, step: 1)
|
|
|
|
Divider()
|
|
|
|
TextField("Notes", text: $notes)
|
|
|
|
// Divider()
|
|
|
|
Spacer()
|
|
|
|
Button("Upload", action: {
|
|
upload(postBody: postData)
|
|
})
|
|
.frame(maxWidth: .infinity, alignment: .center)
|
|
.frame(height: 44)
|
|
.foregroundColor(.blue)
|
|
.background(.yellow)
|
|
.cornerRadius(8)
|
|
.padding()
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
.padding([.leading, .trailing])
|
|
}
|
|
|
|
func upload(postBody: [String: Any]) {
|
|
var _postBody = postBody
|
|
_postBody["difficulty"] = difficulty
|
|
_postBody["notes"] = notes
|
|
|
|
|
|
CompleteWorkoutFetchable(postData: _postBody).fetch(completion: { result in
|
|
switch result {
|
|
case .success(_):
|
|
DispatchQueue.main.async {
|
|
bridgeModule.resetCurrentWorkout()
|
|
dismiss()
|
|
completedWorkoutDismissed?(true)
|
|
}
|
|
case .failure(let failure):
|
|
print(failure)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
//struct CompletedWorkoutView_Previews: PreviewProvider {
|
|
// static let postBody = [
|
|
// "difficulty": 1,
|
|
// "workout_start_time": Date().timeFormatForUpload,
|
|
// "workout": 1,
|
|
// "total_time": 140
|
|
// ] as [String : Any]
|
|
//
|
|
// static let workout = PreviewWorkout.workout()
|
|
//
|
|
// static var previews: some View {
|
|
// CompletedWorkoutView(postData: CompletedWorkoutView_Previews.postBody, workout: workout)
|
|
// }
|
|
//}
|