add NavigationManager for programatic navigation from the root
This commit is contained in:
@@ -11,6 +11,7 @@ import SwiftData
|
||||
struct WorkoutDetail: View {
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
@EnvironmentObject private var navigationManager: NavigationManager
|
||||
|
||||
@Default(\.isWorkingOut) var isWorkingOut
|
||||
|
||||
@@ -73,6 +74,7 @@ struct WorkoutDetail: View {
|
||||
Button(action: {
|
||||
isWorkingOut = true
|
||||
activeWorkoutSession = workout.start()
|
||||
navigationManager.navigateFromRoot(to: .activeWorkoutSession)
|
||||
}) {
|
||||
HStack {
|
||||
Image(systemName: "play.fill")
|
||||
|
||||
@@ -7,10 +7,9 @@
|
||||
|
||||
import SwiftUI
|
||||
|
||||
// TODO: We need color pairs (one for light mode one for dark)
|
||||
struct WorkoutIconSelector: View {
|
||||
|
||||
@State var workout: Workout
|
||||
|
||||
@State private var searchText: String = ""
|
||||
var filteredIcons: [String] {
|
||||
if searchText.isEmpty {
|
||||
|
||||
@@ -10,6 +10,7 @@ import SwiftData
|
||||
|
||||
struct WorkoutLibrary: View {
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
@EnvironmentObject private var navigationManager: NavigationManager
|
||||
@Default(\.isWorkingOut) var isWorkingOut
|
||||
|
||||
@Binding var activeWorkoutSession: WorkoutSession?
|
||||
@@ -44,8 +45,9 @@ struct WorkoutLibrary: View {
|
||||
if !isWorkingOut {
|
||||
Button {
|
||||
activeWorkoutSession = workout.start()
|
||||
navigationManager.navigateFromRoot(to: .activeWorkoutSession)
|
||||
} label: {
|
||||
Label("Start", systemImage: "play")
|
||||
Label("Quick Start Workout", systemImage: "play")
|
||||
.tint(.green)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@ final class WorkoutSessionItem: Nameable, Positionable {
|
||||
var actualReps: Int?
|
||||
var actualValue: Double?
|
||||
|
||||
var startDate: Date?
|
||||
var stopDate: Date?
|
||||
|
||||
init(workoutSession: WorkoutSession, planned: WorkoutItem) {
|
||||
self.workoutSession = workoutSession
|
||||
self.name = planned.exercise.name
|
||||
@@ -33,4 +36,7 @@ final class WorkoutSessionItem: Nameable, Positionable {
|
||||
self.unit = planned.unit
|
||||
self.metric = planned.metric
|
||||
}
|
||||
|
||||
func start() { startDate = .now }
|
||||
func stop() { stopDate = .now }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user