retain order of the exercises during persistence process
This commit is contained in:
@@ -23,16 +23,15 @@ struct WorkoutDetail: View {
|
||||
}
|
||||
Section(header: Text("Exercises")) {
|
||||
List {
|
||||
ForEach(workout.exercises) { exercise in
|
||||
ForEach(workout.exercises
|
||||
.sorted(by: { $0.position < $1.position})) { exercise in
|
||||
ExerciseListItem(workout, exercise)
|
||||
}
|
||||
.onDelete(perform: deleteExerciseFromWorkout)
|
||||
.onMove(perform: move)
|
||||
}
|
||||
.environment(\.editMode, .constant(.active)) // Always active drag mode
|
||||
Button(action: addExerciseToWorkout) {
|
||||
Text("Add Exercise")
|
||||
}
|
||||
AddItemButton(label: "Exercise", action: addExerciseToWorkout)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,7 +76,7 @@ struct WorkoutDetail: View {
|
||||
}
|
||||
|
||||
private func move(from source: IndexSet, to destination: Int) {
|
||||
workout.exercises.move(fromOffsets: source, toOffset: destination)
|
||||
workout.moveExercise(from: source, to: destination)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,19 +94,7 @@ struct ExerciseListItem: View {
|
||||
// workout.addExercise(from: exercise)
|
||||
}) {
|
||||
HStack {
|
||||
|
||||
// TextField("Enter Reps", text: $exercise.reps)
|
||||
// .keyboardType(.numberPad) // Set the keyboard to number pad
|
||||
// .padding()
|
||||
// .frame(width: 100, height: 50)
|
||||
// .background(Color(.systemGray6))
|
||||
// .cornerRadius(8)
|
||||
// .multilineTextAlignment(.center) // Center the text
|
||||
// .overlay(
|
||||
// RoundedRectangle(cornerRadius: 8)
|
||||
// .stroke(Color.gray, lineWidth: 1)
|
||||
// )
|
||||
Text(String(workout.exercises.filter { $0 == exercise }.count))
|
||||
Text(String(exercise.reps))
|
||||
.font(.system(size: 14, weight: .bold))
|
||||
.foregroundStyle(.white)
|
||||
.frame(width: 20, height: 10)
|
||||
@@ -117,7 +104,11 @@ struct ExerciseListItem: View {
|
||||
Text(exercise.name)
|
||||
.foregroundStyle(.black)
|
||||
Spacer()
|
||||
Image(systemName: "info.circle")
|
||||
Stepper(
|
||||
value: $exercise.reps,
|
||||
in: 0...100,
|
||||
step: 1
|
||||
) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user