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

@@ -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