add WorkoutStateManager for ViewModel functionality
This commit is contained in:
@@ -10,10 +10,8 @@ import SwiftData
|
||||
|
||||
struct WorkoutLibrary: View {
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
@Environment(WorkoutStateManager.self) private var workoutStateManager
|
||||
@EnvironmentObject private var navigationManager: NavigationManager
|
||||
@Default(\.isWorkingOut) var isWorkingOut
|
||||
|
||||
@Binding var activeWorkoutSession: WorkoutSession?
|
||||
|
||||
@Query(sort: \Workout.name) private var workouts: [Workout]
|
||||
|
||||
@@ -30,30 +28,29 @@ struct WorkoutLibrary: View {
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
|
||||
Group {
|
||||
List {
|
||||
ForEach(filteredItems) { workout in
|
||||
NavigationLink {
|
||||
WorkoutDetail(activeWorkoutSession: $activeWorkoutSession, workout: workout)
|
||||
WorkoutDetail(workout: workout)
|
||||
} label: {
|
||||
Image(systemName: workout.workoutIconSystemName)
|
||||
.foregroundStyle(workout.workoutIconColorName.color)
|
||||
Text(workout.name)
|
||||
}
|
||||
.swipeActions(edge: .leading) {
|
||||
if !isWorkingOut {
|
||||
Button {
|
||||
activeWorkoutSession = workout.start()
|
||||
navigationManager.navigateFromRoot(to: .activeWorkoutSession)
|
||||
} label: {
|
||||
Label("Quick Start Workout", systemImage: "play")
|
||||
.tint(.green)
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: Add swipe to Quickstart
|
||||
// .swipeActions(edge: .leading) {
|
||||
// if workoutStateManager.isWorkoutInProgress {
|
||||
// Button {
|
||||
// workoutStateManager.start(workout)
|
||||
// navigationManager.navigateFromRoot(to: .activeWorkoutSession)
|
||||
// } label: {
|
||||
// Label("Quick Start Workout", systemImage: "play")
|
||||
// .tint(.green)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
.onDelete(perform: deleteWorkout)
|
||||
if filteredItems.isEmpty {
|
||||
ContentUnavailableView.search(text: searchText)
|
||||
@@ -110,18 +107,21 @@ struct WorkoutLibrary: View {
|
||||
}
|
||||
|
||||
#Preview("With Sample Data") {
|
||||
@Previewable @State var activeWorkoutSession: WorkoutSession?
|
||||
@Previewable @State var stateManager = WorkoutStateManager(modelContext: SampleData.shared.modelContainer.mainContext)
|
||||
NavigationStack {
|
||||
WorkoutLibrary(activeWorkoutSession: $activeWorkoutSession)
|
||||
WorkoutLibrary()
|
||||
}
|
||||
.modelContainer(SampleData.shared.modelContainer)
|
||||
.environment(stateManager)
|
||||
}
|
||||
|
||||
#Preview("Empty Database") {
|
||||
@Previewable @State var activeWorkoutSession: WorkoutSession?
|
||||
@Previewable @State var stateManager = WorkoutStateManager(modelContext: SampleData.shared.modelContainer.mainContext)
|
||||
NavigationStack {
|
||||
WorkoutLibrary(activeWorkoutSession: $activeWorkoutSession)
|
||||
WorkoutLibrary()
|
||||
}
|
||||
// Empty model container to simulate empty workout list
|
||||
.modelContainer(for: Workout.self, inMemory: true)
|
||||
.environment(stateManager)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user