split views into subview
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
54
iphone/Werkout_ios/subview/CaloriesBurnedView.swift
Normal file
54
iphone/Werkout_ios/subview/CaloriesBurnedView.swift
Normal file
@@ -0,0 +1,54 @@
|
||||
//
|
||||
// CaloriesBurnedView.swift
|
||||
// Werkout_ios
|
||||
//
|
||||
// Created by Trey Tartt on 6/18/24.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct CaloriesBurnedView: View {
|
||||
@Binding var healthKitWorkoutData: HealthKitWorkoutData?
|
||||
let calsBurned: Double
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//#Preview {
|
||||
// CaloriesBurnedView()
|
||||
//}
|
||||
56
iphone/Werkout_ios/subview/PlannedWorkoutView.swift
Normal file
56
iphone/Werkout_ios/subview/PlannedWorkoutView.swift
Normal file
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// PlannedWorkoutView.swift
|
||||
// Werkout_ios
|
||||
//
|
||||
// Created by Trey Tartt on 6/18/24.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct PlannedWorkoutView: View {
|
||||
let workouts: [PlannedWorkout]
|
||||
@Binding var selectedPlannedWorkout: Workout?
|
||||
|
||||
var body: 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//#Preview {
|
||||
// PlannedWorkoutView()
|
||||
//}
|
||||
46
iphone/Werkout_ios/subview/RateWorkoutView.swift
Normal file
46
iphone/Werkout_ios/subview/RateWorkoutView.swift
Normal file
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// RateWorkoutView.swift
|
||||
// Werkout_ios
|
||||
//
|
||||
// Created by Trey Tartt on 6/18/24.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct RateWorkoutView: View {
|
||||
@Binding var difficulty: Float
|
||||
|
||||
var body: 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//#Preview {
|
||||
// RateWorkoutView()
|
||||
//}
|
||||
33
iphone/Werkout_ios/subview/WorkoutInfoView.swift
Normal file
33
iphone/Werkout_ios/subview/WorkoutInfoView.swift
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// WorkoutInfoView.swift
|
||||
// Werkout_ios
|
||||
//
|
||||
// Created by Trey Tartt on 6/18/24.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct WorkoutInfoView: View {
|
||||
let workout: Workout
|
||||
|
||||
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)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//#Preview {
|
||||
// WorkoutInfoView()
|
||||
//}
|
||||
Reference in New Issue
Block a user