wip
This commit is contained in:
@ -13,49 +13,45 @@ import SwiftData
|
||||
struct ContentView: View {
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
|
||||
@State var activeWorkouts: [Workout] = []
|
||||
@State var workouts: [Workout] = []
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
if activeWorkouts.isEmpty {
|
||||
NoActiveWorkoutView()
|
||||
if workouts.isEmpty {
|
||||
NoWorkoutView()
|
||||
} else {
|
||||
ActiveWorkoutListView(workouts: activeWorkouts)
|
||||
ActiveWorkoutListView(workouts: workouts)
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
loadActiveWorkouts()
|
||||
loadWorkouts()
|
||||
}
|
||||
}
|
||||
|
||||
func loadActiveWorkouts () {
|
||||
let completedStatus = WorkoutStatus.completed.rawValue
|
||||
func loadWorkouts () {
|
||||
do {
|
||||
self.activeWorkouts = try modelContext.fetch(FetchDescriptor<Workout>(
|
||||
predicate: #Predicate<Workout> { workout in
|
||||
workout.status != completedStatus
|
||||
},
|
||||
self.workouts = try modelContext.fetch(FetchDescriptor<Workout>(
|
||||
sortBy: [
|
||||
SortDescriptor(\Workout.start, order: .reverse)
|
||||
]
|
||||
))
|
||||
} catch {
|
||||
print("ERROR: failed to load active workouts \(error)")
|
||||
print("ERROR: failed to load workouts \(error)")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct NoActiveWorkoutView: View {
|
||||
struct NoWorkoutView: View {
|
||||
var body: some View {
|
||||
VStack(spacing: 16) {
|
||||
Image(systemName: "dumbbell.fill")
|
||||
.font(.system(size: 40))
|
||||
.foregroundStyle(.gray)
|
||||
|
||||
Text("No Active Workout")
|
||||
Text("No Workouts")
|
||||
.font(.headline)
|
||||
|
||||
Text("Start a workout in the main app")
|
||||
Text("Create a workout in the main app")
|
||||
.font(.caption)
|
||||
.foregroundStyle(.gray)
|
||||
.multilineTextAlignment(.center)
|
||||
|
Reference in New Issue
Block a user