WIP
This commit is contained in:
@@ -164,9 +164,9 @@
|
|||||||
1CF65A3B2A3972CE0042FFBD /* ExternalWorkoutDetailView.swift */,
|
1CF65A3B2A3972CE0042FFBD /* ExternalWorkoutDetailView.swift */,
|
||||||
1CF65A622A3BF6A30042FFBD /* AllWorkoutsView.swift */,
|
1CF65A622A3BF6A30042FFBD /* AllWorkoutsView.swift */,
|
||||||
1CF65A4B2A39FDA20042FFBD /* WorkoutDetailView.swift */,
|
1CF65A4B2A39FDA20042FFBD /* WorkoutDetailView.swift */,
|
||||||
|
1CF65A4D2A39FF200042FFBD /* WorkoutDetailViewModel.swift */,
|
||||||
1CF65A6C2A3F60100042FFBD /* CreateWorkoutViews */,
|
1CF65A6C2A3F60100042FFBD /* CreateWorkoutViews */,
|
||||||
1CF65A602A3BF6020042FFBD /* AddExerciseView.swift */,
|
1CF65A602A3BF6020042FFBD /* AddExerciseView.swift */,
|
||||||
1CF65A4D2A39FF200042FFBD /* WorkoutDetailViewModel.swift */,
|
|
||||||
1CF65A682A3C018F0042FFBD /* AccountView.swift */,
|
1CF65A682A3C018F0042FFBD /* AccountView.swift */,
|
||||||
);
|
);
|
||||||
path = Views;
|
path = Views;
|
||||||
|
|||||||
@@ -8,13 +8,14 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
struct Workout: Codable {
|
struct Workout: Codable {
|
||||||
|
let id: Int
|
||||||
let name: String
|
let name: String
|
||||||
let description: String?
|
let description: String?
|
||||||
let exercises: [ExerciseElement]
|
let exercises: [ExerciseElement]
|
||||||
let registeredUser: RegisteredUser
|
let registeredUser: RegisteredUser
|
||||||
|
|
||||||
enum CodingKeys: String, CodingKey {
|
enum CodingKeys: String, CodingKey {
|
||||||
case name, description, exercises
|
case name, description, exercises, id
|
||||||
case registeredUser = "registered_user"
|
case registeredUser = "registered_user"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,6 +30,7 @@ struct Workout: Codable {
|
|||||||
self.name = try container.decode(String.self, forKey: .name)
|
self.name = try container.decode(String.self, forKey: .name)
|
||||||
self.description = try container.decodeIfPresent(String.self, forKey: .description)
|
self.description = try container.decodeIfPresent(String.self, forKey: .description)
|
||||||
self.registeredUser = try container.decode(RegisteredUser.self, forKey: .registeredUser)
|
self.registeredUser = try container.decode(RegisteredUser.self, forKey: .registeredUser)
|
||||||
|
self.id = try container.decode(Int.self, forKey: .id)
|
||||||
}
|
}
|
||||||
|
|
||||||
var exercisesSortedByCreated_at: [ExerciseElement] {
|
var exercisesSortedByCreated_at: [ExerciseElement] {
|
||||||
|
|||||||
@@ -16,8 +16,8 @@ class WorkoutDetailFetchable: Fetchable {
|
|||||||
typealias Response = Workout
|
typealias Response = Workout
|
||||||
var endPoint: String
|
var endPoint: String
|
||||||
|
|
||||||
init(workoutID: String) {
|
init(workoutID: Int) {
|
||||||
self.endPoint = "/workout/"+workoutID+"/details/"
|
self.endPoint = "workout/"+String(workoutID)+"/details/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -41,7 +41,16 @@ struct AllWorkoutsView: View {
|
|||||||
Text("no workouts")
|
Text("no workouts")
|
||||||
}
|
}
|
||||||
}.onAppear{
|
}.onAppear{
|
||||||
testParse()
|
AllWorkoutFetchable().fetch(completion: { result in
|
||||||
|
switch result {
|
||||||
|
case .success(let model):
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.workouts = model
|
||||||
|
}
|
||||||
|
case .failure(let failure):
|
||||||
|
fatalError("shit broke")
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
.sheet(isPresented: $showWorkoutDetail) {
|
.sheet(isPresented: $showWorkoutDetail) {
|
||||||
if let selectedWorkout = selectedWorkout {
|
if let selectedWorkout = selectedWorkout {
|
||||||
@@ -52,7 +61,7 @@ struct AllWorkoutsView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func selectedItem(workout: Workout) {
|
func selectedItem(workout: Workout) {
|
||||||
selectedWorkout = PreviewWorkout.workout()
|
selectedWorkout = workout
|
||||||
}
|
}
|
||||||
|
|
||||||
func testParse() {
|
func testParse() {
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ struct WorkoutDetailView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var body: some View {
|
var body: some View {
|
||||||
|
ZStack {
|
||||||
|
switch viewModel.status {
|
||||||
|
case .loading:
|
||||||
|
Text("Loading")
|
||||||
|
case .showWorkout(let workout):
|
||||||
VStack {
|
VStack {
|
||||||
HStack {
|
HStack {
|
||||||
Button("i dont want to do this", action: {
|
Button("i dont want to do this", action: {
|
||||||
@@ -36,8 +41,8 @@ struct WorkoutDetailView: View {
|
|||||||
}
|
}
|
||||||
.frame(height: 88)
|
.frame(height: 88)
|
||||||
List() {
|
List() {
|
||||||
ForEach(viewModel.workout.exercisesSortedByCreated_at.indices, id: \.self) { i in
|
ForEach(workout.exercisesSortedByCreated_at.indices, id: \.self) { i in
|
||||||
let obj = viewModel.workout.exercisesSortedByCreated_at[i]
|
let obj = workout.exercisesSortedByCreated_at[i]
|
||||||
Text(obj.exercise.name ?? "")
|
Text(obj.exercise.name ?? "")
|
||||||
.onTapGesture { selectedIdx = i }
|
.onTapGesture { selectedIdx = i }
|
||||||
}
|
}
|
||||||
@@ -57,15 +62,23 @@ struct WorkoutDetailView: View {
|
|||||||
}
|
}
|
||||||
.interactiveDismissDisabled()
|
.interactiveDismissDisabled()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func runItemAt(idx: Int) {
|
func runItemAt(idx: Int) {
|
||||||
if idx < viewModel.workout.exercises.count {
|
switch viewModel.status {
|
||||||
let exercise = viewModel.workout.exercises[idx]
|
case .showWorkout(let workout):
|
||||||
|
if idx < workout.exercises.count {
|
||||||
|
let exercise = workout.exercises[idx]
|
||||||
bridgeModule.updateCurrent(exercise: exercise)
|
bridgeModule.updateCurrent(exercise: exercise)
|
||||||
bridgeModule.currentExerciseIdx = idx
|
bridgeModule.currentExerciseIdx = idx
|
||||||
} else {
|
} else {
|
||||||
workoutComplete()
|
workoutComplete()
|
||||||
}
|
}
|
||||||
|
default:
|
||||||
|
fatalError("no workout!!")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func workoutComplete() {
|
private func workoutComplete() {
|
||||||
|
|||||||
@@ -9,9 +9,24 @@ import Combine
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
class WorkoutDetailViewModel: ObservableObject {
|
class WorkoutDetailViewModel: ObservableObject {
|
||||||
@Published var workout: Workout
|
enum WorkoutDetailViewModelStatus {
|
||||||
|
case loading
|
||||||
|
case showWorkout(Workout)
|
||||||
|
}
|
||||||
|
@Published var status: WorkoutDetailViewModelStatus
|
||||||
|
|
||||||
init(workout: Workout) {
|
init(workout: Workout) {
|
||||||
self.workout = workout
|
self.status = .loading
|
||||||
|
|
||||||
|
WorkoutDetailFetchable(workoutID: workout.id).fetch(completion: { result in
|
||||||
|
switch result {
|
||||||
|
case .success(let model):
|
||||||
|
DispatchQueue.main.async {
|
||||||
|
self.status = .showWorkout(model)
|
||||||
|
}
|
||||||
|
case .failure(let failure):
|
||||||
|
fatalError("failed \(failure.localizedDescription)")
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user