// // ContentView.swift // WorkoutsPlus // // Created by Felix Förtsch on 13.08.24. // import SwiftUI import SwiftData struct ContentView: View { @Environment(\.modelContext) private var modelContext @StateObject private var navigationManager = NavigationManager() @Default(\.isOnboarding) var isOnboarding @Default(\.isWorkingOut) var isWorkingOut @State var activeWorkoutSession: WorkoutSession? var body: some View { NavigationStack(path: $navigationManager.path) { List { Section { VStack { HStack { Image(systemName: "person.crop.circle.badge.plus") .resizable() .aspectRatio(contentMode: .fill) .frame(width: 50, height: 50) .padding(.horizontal) .foregroundStyle(.blue) VStack(alignment: .leading) { Text("Felix Förtsch") .font(.title) .fontWeight(.bold) Text("You got this!") .font(.headline) .foregroundStyle(.secondary) } } .padding(.vertical, 5) // TODO: Food Log (Foto + Kalender + Macros // TODO: Goal page // ActivityLog() // .frame(height: 200) } } // MARK: Workout Controls if let _ = activeWorkoutSession { Section { NavigationLink( destination: ActiveWorkoutSession( activeWorkoutSession: Binding( get: { activeWorkoutSession! }, set: { activeWorkoutSession = $0 })) ) { HStack { Label("Back to Session", systemImage: "memories") .symbolEffect(.rotate) Text("35 min") .font(.subheadline) .foregroundStyle(.secondary) } } ActiveWorkoutSessionControls( session: Binding( get: { activeWorkoutSession! }, set: { activeWorkoutSession = $0 } )) } } else { Section(footer: Text("Starts the next planned workout immediately.")) { Label("Quick Start", systemImage: "play") } } Section { NavigationLink(value: NavigationDestination.workoutLog) { Label("Workout Log", systemImage: "calendar.badge.clock") } NavigationLink(value: NavigationDestination.workoutLibrary) { Label("Workouts", systemImage: "figure.run.square.stack") } NavigationLink(value: NavigationDestination.exerciseLibrary) { Label("Exercises", systemImage: "figure.run") } } Section { Label("Food Log", systemImage: "list.bullet.clipboard") NavigationLink(destination: Label("Add Food", systemImage: "plus")) { Label("Food Library", systemImage: "fork.knife") } } Section { NavigationLink(value: NavigationDestination.settings) { Label("Settings", systemImage: "gear") } NavigationLink(value: NavigationDestination.debug) { Label("Debug", systemImage: "hammer") } } } .navigationBarTitleDisplayMode(.large) .toolbar { ToolbarItem(placement: .topBarLeading) { HStack { ZStack { Image(systemName: "hexagon.fill") .resizable() .aspectRatio(contentMode: .fill) .frame(width: 35, height: 35) .foregroundStyle(systemColors.randomElement()!) Image(systemName: fitnessIcons.randomElement()!) .foregroundStyle(.white) } Text("Workout+") .font(.title) .fontWeight(.bold) } } } .navigationDestination(for: NavigationDestination.self) { destination in switch destination { case .activeWorkoutSession: if let _ = activeWorkoutSession { ActiveWorkoutSession(activeWorkoutSession: Binding( get: { activeWorkoutSession! }, set: { activeWorkoutSession = $0 } )) } case .workoutLibrary: WorkoutLibrary(activeWorkoutSession: $activeWorkoutSession) case .workoutLog: WorkoutLogs() case .exerciseLibrary: ExerciseLibrary() case .settings: Settings() case .debug: DebugList() } } } .environmentObject(navigationManager) .sheet(isPresented: $isOnboarding) { Onboarding() } } } #Preview("No Workout Session") { ContentView() .onAppear { Defaults.shared.isWorkingOut = false } .modelContainer(SampleData.shared.modelContainer) } #Preview("With Active Workout Session") { ContentView() .onAppear { Defaults.shared.isWorkingOut = true } .modelContainer(SampleData.shared.modelContainer) }