67 lines
1.5 KiB
Swift
67 lines
1.5 KiB
Swift
//
|
|
// ContentView.swift
|
|
// Workouts
|
|
//
|
|
// Created by rzen on 7/15/25 at 7:09 PM.
|
|
//
|
|
// Copyright 2025 Rouslan Zenetl. All Rights Reserved.
|
|
//
|
|
|
|
import SwiftUI
|
|
import SwiftData
|
|
|
|
struct ContentView: View {
|
|
@Environment(\.modelContext) private var modelContext
|
|
|
|
@State var workouts: [Workout] = []
|
|
|
|
var body: some View {
|
|
NavigationStack {
|
|
if workouts.isEmpty {
|
|
NoWorkoutView()
|
|
} else {
|
|
ActiveWorkoutListView(workouts: workouts)
|
|
}
|
|
}
|
|
.onAppear {
|
|
loadWorkouts()
|
|
}
|
|
}
|
|
|
|
func loadWorkouts () {
|
|
do {
|
|
self.workouts = try modelContext.fetch(FetchDescriptor<Workout>(
|
|
sortBy: [
|
|
SortDescriptor(\Workout.start, order: .reverse)
|
|
]
|
|
))
|
|
} catch {
|
|
print("ERROR: failed to load workouts \(error)")
|
|
}
|
|
}
|
|
}
|
|
|
|
struct NoWorkoutView: View {
|
|
var body: some View {
|
|
VStack(spacing: 16) {
|
|
Image(systemName: "dumbbell.fill")
|
|
.font(.system(size: 40))
|
|
.foregroundStyle(.gray)
|
|
|
|
Text("No Workouts")
|
|
.font(.headline)
|
|
|
|
Text("Create a workout in the main app")
|
|
.font(.caption)
|
|
.foregroundStyle(.gray)
|
|
.multilineTextAlignment(.center)
|
|
}
|
|
.padding()
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
ContentView()
|
|
.modelContainer(AppContainer.preview)
|
|
}
|