split views into subview

This commit is contained in:
Trey t
2024-06-18 14:31:27 -05:00
parent 7d2b6b3e6e
commit 48cc22b3e2
7 changed files with 226 additions and 136 deletions

View File

@@ -81,7 +81,8 @@ struct AllWorkoutsView: View {
})
Divider()
case .MyWorkouts:
plannedWorkout(workouts: UserStore.shared.plannedWorkouts)
PlannedWorkoutView(workouts: UserStore.shared.plannedWorkouts,
selectedPlannedWorkout: $selectedPlannedWorkout)
}
}
} else {
@@ -93,7 +94,7 @@ struct AllWorkoutsView: View {
maybeUpdateShit()
}
.sheet(item: $selectedWorkout) { item in
var isPreview = item.id == bridgeModule.currentExerciseInfo.workout?.id
let isPreview = item.id == bridgeModule.currentExerciseInfo.workout?.id
let viewModel = WorkoutDetailViewModel(workout: item, isPreview: isPreview)
WorkoutDetailView(viewModel: viewModel)
}
@@ -113,46 +114,7 @@ struct AllWorkoutsView: View {
maybeUpdateShit()
}
}
func plannedWorkout(workouts: [PlannedWorkout]) -> some View {
List {
ForEach(workouts, id:\.workout.name) { plannedWorkout in
HStack {
VStack(alignment: .leading) {
Text(plannedWorkout.onDate.plannedDate?.weekDay ?? "-")
.font(.title)
Text(plannedWorkout.onDate.plannedDate?.monthString ?? "-")
.font(.title)
Text(plannedWorkout.onDate.plannedDate?.dateString ?? "-")
.font(.title)
}
Divider()
VStack {
Text(plannedWorkout.workout.name)
.font(.title)
.frame(maxWidth: .infinity, alignment: .leading)
Text(plannedWorkout.workout.description ?? "")
.font(.body)
.frame(maxWidth: .infinity, alignment: .leading)
Text(plannedWorkout.onDate)
.font(.footnote)
.frame(maxWidth: .infinity, alignment: .leading)
}
.contentShape(Rectangle())
.onTapGesture {
selectedPlannedWorkout = plannedWorkout.workout
}
}
}
}
}
func maybeUpdateShit() {
if UserStore.shared.token != nil{
if UserStore.shared.plannedWorkouts.isEmpty {