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 {

View File

@@ -29,48 +29,18 @@ struct CompletedWorkoutView: View {
ProgressView("Uploading")
}
VStack {
topViews()
WorkoutInfoView(workout: workout)
Divider()
HStack {
if let calsBurned = healthKitWorkoutData?.caloriesBurned {
HStack {
HStack {
Image(systemName: "flame.fill")
.foregroundColor(.orange)
.font(.title)
VStack {
Text("\(calsBurned, specifier: "%.0f")")
}
}
.frame(maxWidth: .infinity)
}
if let minHeart = healthKitWorkoutData?.minHeartRate,
let maxHeart = healthKitWorkoutData?.maxHeartRate,
let avgHeart = healthKitWorkoutData?.avgHeartRate {
VStack {
HStack {
Image(systemName: "heart")
.foregroundColor(.red)
.font(.title)
VStack {
HStack {
Text("\(minHeart, specifier: "%.0f")")
Text("-")
Text("\(maxHeart, specifier: "%.0f")")
}
Text("\(avgHeart, specifier: "%.0f")")
}
}
}
.frame(maxWidth: .infinity)
}
CaloriesBurnedView(healthKitWorkoutData: $healthKitWorkoutData,
calsBurned: calsBurned)
}
}
rateWorkout()
RateWorkoutView(difficulty: $difficulty)
.frame(maxHeight: 88)
Divider()
@@ -117,53 +87,6 @@ struct CompletedWorkoutView: View {
}
})
}
func topViews() -> 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)
}
}
}
func rateWorkout() -> some View {
VStack {
Divider()
HStack {
Text("No Rate")
.foregroundColor(.black)
Text("Easy")
.foregroundColor(.green)
Spacer()
Text("Death")
.foregroundColor(.red)
}
ZStack {
LinearGradient(
gradient: Gradient(colors: [.black, .green, .red]),
startPoint: .leading,
endPoint: .trailing
)
.mask(Slider(value: $difficulty, in: 0...5, step: 1))
// Dummy replicated slider, to allow sliding
Slider(value: $difficulty, in: 0...5, step: 1)
.opacity(0.05) // Opacity is the trick here.
.accentColor(.clear)
}
}
}
func upload(postBody: [String: Any]) {
var _postBody = postBody