Files
workoutsplus/WorkoutsPlus/ContentView.swift

143 lines
4.2 KiB
Swift

//
// ContentView.swift
// WorkoutsPlus
//
// Created by Felix Förtsch on 13.08.24.
//
import SwiftUI
import SwiftData
struct ContentView: View {
@Environment(\.modelContext) private var modelContext
@Default(\.isOnboarding) var isOnboarding
@Default(\.isWorkingOut) var isWorkingOut
@State var activeWorkoutSession: WorkoutSession?
var body: some View {
NavigationStack {
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: $activeWorkoutSession,
activeWorkout: activeWorkoutSession.workout)
) {
HStack {
Label("Back to Session", systemImage: "memories")
.symbolEffect(.rotate)
Text("35 min")
.font(.subheadline)
.foregroundStyle(.secondary)
}
}
ActiveWorkoutSessionControls(
session: Binding(
get: { self.activeWorkoutSession! },
set: { self.activeWorkoutSession = $0 }
))
}
} else {
Section(footer: Text("Starts the next planned workout immediately.")) {
Label("Quick Start", systemImage: "play")
}
}
Section {
NavigationLink(destination: WorkoutLog()) {
Label("Workout Log", systemImage: "calendar.badge.clock")
}
NavigationLink(destination: WorkoutLibrary(activeWorkoutSession: $activeWorkoutSession)) {
Label("Workouts", systemImage: "figure.run.square.stack")
}
NavigationLink(destination: 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(destination: Settings()) {
Label("Settings", systemImage: "gear")
}
NavigationLink(destination: DebugList()) {
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)
}
}
}
}
.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)
}