add ExerciseEditor, Picker skeletons, AutocompleteTextfield

This commit is contained in:
Felix Förtsch
2024-09-23 11:41:34 +02:00
parent 41b97964c4
commit 4a42fc6c33
20 changed files with 527 additions and 164 deletions

View File

@@ -20,32 +20,22 @@ struct ActiveWorkoutSession: View {
List {
Section(header: Text("Workout"), footer: Text(activeWorkoutSession?.creationDate.ISO8601Format() ?? "Unknown Date")) {
NavigationLink(destination: {
ItemPicker<Workout>(items: workouts, selectedItem: $activeWorkout)
ItemPicker<Workout>(selectedItem: $activeWorkout, items: workouts)
}) {
Text(activeWorkout?.name ?? "Select Workout")
}
.onChange(of: activeWorkout) { _, newWorkout in
if let workout = newWorkout {
activeWorkoutId = workout.id.uuidString
activeWorkoutSession?.workout = workout
if let newWorkout {
activeWorkoutId = newWorkout.id.uuidString
activeWorkoutSession?.workout = newWorkout
}
}
}
if let activeWorkout = activeWorkout {
if let activeWorkout {
Section(header: Text("Exercises")) {
ForEach(getActiveWorkoutItems(activeWorkout: activeWorkout)) { workoutItem in
HStack {
Text(String(workoutItem.reps))
Text(workoutItem.name)
Spacer()
Button(action: {
// TODO: Implement a sheet view; don't use ExerciseDetail since its purpose is editing
}) {
Image(systemName: "info.circle")
.foregroundColor(.blue)
}
}
ActiveWorkoutSessionListItem(workoutItem: workoutItem)
}
}
} else {
@@ -54,14 +44,14 @@ struct ActiveWorkoutSession: View {
}
}
}
// MARK: -- Workout Controls
// MARK: Workout Controls
if (isWorkingOut) {
if activeWorkoutSession != nil {
ActiveWorkoutSessionControls(
session: Binding(
get: { self.activeWorkoutSession! },
set: { self.activeWorkoutSession = $0 }
))
get: { self.activeWorkoutSession! },
set: { self.activeWorkoutSession = $0 }
))
}
}
}
@@ -78,11 +68,14 @@ struct ActiveWorkoutSession: View {
}
}
.bold()
.fontDesign(.rounded)
.tint(.red)
} else {
Button(action: {
isWorkingOut = true
activeWorkoutSession?.start()
if let activeWorkout {
activeWorkoutSession?.start(with: activeWorkout)
}
}) {
HStack {
Image(systemName: "play.fill")
@@ -90,11 +83,11 @@ struct ActiveWorkoutSession: View {
}
}
.bold()
.fontDesign(.rounded)
.tint(.green)
}
}
.onAppear {
// Load the active workout session and workout onAppear
if let activeWorkoutSession = getItem(from: workoutSessions, by: activeWorkoutSessionId) {
self.activeWorkoutSession = activeWorkoutSession
if let workout = getItem(from: workouts, by: activeWorkoutId) {
@@ -132,6 +125,9 @@ struct ActiveWorkoutSession: View {
NavigationStack {
ActiveWorkoutSession(activeWorkout: activeWorkout)
}
.onAppear {
Defaults.shared.isWorkingOut = false
}
.modelContainer(SampleData.shared.modelContainer)
}