fix repetitive save of WorkoutItem, add: Onboarding, Defaults, Settings, Trainer/Trainee skeletons, reorder files, remove all Bindable
This commit is contained in:
@@ -12,54 +12,38 @@ struct AddWorkoutItemToWorkout: View {
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
@Query(sort: \Exercise.name) private var exercises: [Exercise]
|
||||
|
||||
@Bindable var workout: Workout
|
||||
@State var workout: Workout
|
||||
// TODO: Add (i) Button that allows editing an exercise (maybe requires NavigationStack?)
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
List {
|
||||
Section(header: Text("Utilities")) {
|
||||
AddExerciseToWorkoutListItem(WorkoutItem(workoutItems: []), workout)
|
||||
// AddExerciseToWorkoutListItem(WorkoutItem(workoutItems: []), workout)
|
||||
}
|
||||
Section(header: Text("Excersises")) {
|
||||
if !exercises.isEmpty {
|
||||
ForEach(exercises) { exercise in
|
||||
|
||||
AddExerciseToWorkoutListItem(WorkoutItem(from: exercise), workout)
|
||||
}} else {
|
||||
ContentUnavailableView {
|
||||
// TODO: Add Button that allows adding an exercise
|
||||
Label("No Exercises", systemImage: Exercise.systemImage)
|
||||
AddItemButton(label: exercise.name) {
|
||||
let workoutItem = WorkoutItem(from: exercise)
|
||||
addWorkoutItemtoWorkout(workoutItem)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ContentUnavailableView {
|
||||
// TODO: Add Button that allows adding an exercise
|
||||
Label("No Exercises", systemImage: Exercise.systemImage)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct AddExerciseToWorkoutListItem: View {
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
|
||||
var workoutItem: WorkoutItem
|
||||
var workout: Workout
|
||||
|
||||
init(_ workoutItem: WorkoutItem, _ workout: Workout) {
|
||||
self.workoutItem = workoutItem
|
||||
self.workout = workout
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Button(action: {
|
||||
workout.add(workoutItem: workoutItem)
|
||||
}) {
|
||||
HStack {
|
||||
Text(workoutItem.name)
|
||||
.foregroundStyle(.black)
|
||||
Spacer()
|
||||
Image(systemName: "plus.circle.fill")
|
||||
.foregroundStyle(.green)
|
||||
}
|
||||
}
|
||||
private func addWorkoutItemtoWorkout(_ workoutItem: WorkoutItem) {
|
||||
workout.add(workoutItem: workoutItem)
|
||||
// TODO: Handle saving in a way the user knows when it's saved
|
||||
// modelContext.save()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user