refactor WorkoutItemLibrarySheet, add Set sample data

This commit is contained in:
Felix Förtsch
2024-09-07 11:27:01 +02:00
parent 87f1922a61
commit 03cc854c66
4 changed files with 30 additions and 17 deletions
+12 -12
View File
@@ -13,7 +13,7 @@ struct WorkoutDetail: View {
@Environment(\.modelContext) private var modelContext
@State var workout: Workout
@State private var isPresentingExerciseLibrary = false
@State private var isPresentingWorkoutItemLibrarySheet = false
var body: some View {
List {
@@ -25,7 +25,9 @@ struct WorkoutDetail: View {
.foregroundStyle(workout.workoutIconColorName.color)
}
}
Section(header: Text("Exercises")) {
Section(
header: Text("Exercises"),
footer: Text("Drag and drop to re-arrange or swipe to delete exercises.")) {
ForEach(workout.workoutItems
.sorted(by: { $0.position < $1.position})) { workoutItem in
switch workoutItem.workoutItemType {
@@ -40,25 +42,23 @@ struct WorkoutDetail: View {
.onDelete(perform: deleteExerciseFromWorkout)
.onMove(perform: move)
.environment(\.editMode, .constant(.active)) // Always active drag mode
AddItemButton(label: "Exercise", action: addWorkoutItemToWorkout)
AddItemButton(label: "Exercise", action: presentWorkoutItemLibrarySheet)
}
}
.navigationBarTitle("\(workout.name)")
.toolbar {
ToolbarItem() {
EditButton()
}
// TODO: Add proper Sharing for workouts.
ToolbarItem() { ShareLink(item: URL(filePath: "felixfoertsch.de")!) }
ToolbarItem() { EditButton() }
}
.sheet(isPresented: $isPresentingExerciseLibrary) {
AddWorkoutItemToWorkout(workout: workout)
.presentationDetents([.medium, .large])
.presentationDragIndicator(.visible)
.sheet(isPresented: $isPresentingWorkoutItemLibrarySheet) {
WorkoutItemLibrarySheet(workout: workout)
}
}
private func addWorkoutItemToWorkout() {
private func presentWorkoutItemLibrarySheet() {
withAnimation {
isPresentingExerciseLibrary = true
isPresentingWorkoutItemLibrarySheet = true
}
}