WIP
This commit is contained in:
@@ -95,4 +95,29 @@ class WorkoutViewModel: ObservableObject {
|
||||
superSets.remove(at: idx)
|
||||
}
|
||||
}
|
||||
|
||||
func uploadWorkout() {
|
||||
var exercises = [[String: Any]]()
|
||||
superSets.forEach({ superset in
|
||||
for _ in 0 ..< superset.numberOfRounds {
|
||||
for exercise in superset.exercises {
|
||||
let item = ["id": exercise.exercise.id, "reps": exercise.reps, "weight": exercise.weight, "duration": exercise.duration] as [String : Any]
|
||||
exercises.append(item)
|
||||
}
|
||||
}
|
||||
})
|
||||
let uploadBody = ["name": title, "description": "description", "exercise_data": exercises] as [String : Any]
|
||||
CreateWorkoutFetchable(postData: uploadBody).fetch(completion: { result in
|
||||
DispatchQueue.main.async {
|
||||
switch result {
|
||||
case .success(_):
|
||||
self.superSets.removeAll()
|
||||
self.title = ""
|
||||
NotificationCenter.default.post(name: NSNotification.Name("CreatedNewWorkout"), object: nil, userInfo: nil)
|
||||
case .failure(let failure):
|
||||
print(failure)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ struct CreateWorkoutMainView: View {
|
||||
Divider()
|
||||
|
||||
Button("Done", action: {
|
||||
|
||||
viewModel.uploadWorkout()
|
||||
})
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.frame(height: 44)
|
||||
|
||||
Reference in New Issue
Block a user