WIP
This commit is contained in:
68
Werkout_ios/subview/CompletedWorkoutsView.swift
Normal file
68
Werkout_ios/subview/CompletedWorkoutsView.swift
Normal file
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// CompletedWorkoutsView.swift
|
||||
// Werkout_ios
|
||||
//
|
||||
// Created by Trey Tartt on 6/16/24.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct CompletedWorkoutsView: View {
|
||||
@State var completedWorkouts: [CompletedWorkout]?
|
||||
@State var showCompletedWorkouts: Bool = false
|
||||
|
||||
var body: some View {
|
||||
if let completedWorkouts = completedWorkouts {
|
||||
VStack(alignment: .leading) {
|
||||
Divider()
|
||||
Text("Workout History:")
|
||||
HStack {
|
||||
Text("Number of workouts:")
|
||||
Text("\(completedWorkouts.count)")
|
||||
}
|
||||
|
||||
if let lastWorkout = completedWorkouts.last {
|
||||
HStack {
|
||||
Text("Last workout:")
|
||||
Text(lastWorkout.workoutStartTime)
|
||||
}
|
||||
|
||||
Button("View All Workouts", action: {
|
||||
showCompletedWorkouts = true
|
||||
})
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.frame(height: 44)
|
||||
.foregroundColor(.blue)
|
||||
.background(.yellow)
|
||||
.cornerRadius(8)
|
||||
.padding()
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
|
||||
}
|
||||
.onAppear{
|
||||
fetchCompletedWorkouts()
|
||||
}
|
||||
.sheet(isPresented: $showCompletedWorkouts) {
|
||||
if completedWorkouts.count > 0 {
|
||||
WorkoutHistoryView(completedWorkouts: completedWorkouts)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func fetchCompletedWorkouts() {
|
||||
CompletedWorkoutFetchable().fetch(completion: { result in
|
||||
switch result {
|
||||
case .success(let model):
|
||||
completedWorkouts = model
|
||||
case .failure(let failure):
|
||||
fatalError(failure.localizedDescription)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
CompletedWorkoutsView()
|
||||
}
|
||||
Reference in New Issue
Block a user