clean up ActiveWorkoutSession
This commit is contained in:
109
WorkoutsPlus/Features/WorkoutLog/WorkoutLogs.swift
Normal file
109
WorkoutsPlus/Features/WorkoutLog/WorkoutLogs.swift
Normal file
@@ -0,0 +1,109 @@
|
||||
//
|
||||
// WorkoutLog.swift
|
||||
// WorkoutsPlus
|
||||
//
|
||||
// Created by Felix Förtsch on 30.08.24.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import SwiftData
|
||||
|
||||
struct WorkoutLogs: View {
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
@Query(sort: \WorkoutSession.name) private var workoutSessions: [WorkoutSession]
|
||||
|
||||
@Default(\.isWorkingOut) var isWorkingOut
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
Section(header: Text("Dummies")) {
|
||||
NavigationLink(destination: Text("WorkoutLogDetails")) {
|
||||
HStack(alignment: .top) {
|
||||
Image(systemName: "figure.run")
|
||||
.padding(.trailing)
|
||||
.padding(.top)
|
||||
VStack(alignment: .leading) {
|
||||
HStack {
|
||||
Text("23.01.1988")
|
||||
Text("14:37 Uhr")
|
||||
Spacer()
|
||||
}
|
||||
Text("Marathon")
|
||||
.fontWeight(.semibold)
|
||||
HStack {
|
||||
Text("34 km/42 km")
|
||||
Text("•")
|
||||
Text("5:12 min/km")
|
||||
}.foregroundStyle(.gray)
|
||||
HStack {
|
||||
Text("1 h")
|
||||
Text("•")
|
||||
Text("1.337 kcal")
|
||||
}
|
||||
.foregroundStyle(.gray)
|
||||
}
|
||||
}
|
||||
}
|
||||
NavigationLink(destination: Text("WorkoutLogDetails")) {
|
||||
HStack {
|
||||
Image(systemName: "figure.run")
|
||||
.padding(.trailing)
|
||||
VStack(alignment: .leading) {
|
||||
HStack {
|
||||
Text("23.01.1988")
|
||||
Text("14:37 Uhr")
|
||||
Spacer()
|
||||
}
|
||||
Text("Recommended Routine")
|
||||
.fontWeight(.semibold)
|
||||
HStack {
|
||||
Text("6/12 sets")
|
||||
Text("•")
|
||||
Text("50 %")
|
||||
}.foregroundStyle(.gray)
|
||||
HStack {
|
||||
Text("57 m")
|
||||
Text("•")
|
||||
Text("357 kcal")
|
||||
}
|
||||
.foregroundStyle(.gray)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Section(header: Text("Workout Sessions")) {
|
||||
ForEach(workoutSessions) { session in
|
||||
VStack(alignment: .leading) {
|
||||
Text(session.startDate.ISO8601Format())
|
||||
Text(session.name)
|
||||
.font(.subheadline)
|
||||
}
|
||||
}.onDelete(perform: deleteWorkoutSession)
|
||||
}
|
||||
|
||||
}
|
||||
.navigationTitle("Workout Logs")
|
||||
}
|
||||
|
||||
private func deleteWorkoutSession(offsets: IndexSet) {
|
||||
withAnimation {
|
||||
for index in offsets {
|
||||
modelContext.delete(workoutSessions[index])
|
||||
}
|
||||
try? modelContext.save()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview("Active WorkoutSession") {
|
||||
NavigationStack {
|
||||
WorkoutLogs()
|
||||
.onAppear {
|
||||
Defaults.shared.isWorkingOut = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview("No Active WorkoutSession") {
|
||||
WorkoutLogs()
|
||||
}
|
||||
Reference in New Issue
Block a user