wip
This commit is contained in:
@ -48,8 +48,11 @@ extension Split: EditableEntity {
|
||||
|
||||
fileprivate struct SplitFormView: View {
|
||||
@Binding var model: Split
|
||||
|
||||
@State private var showingAddSheet: Bool = false
|
||||
@State private var itemToEdit: SplitExerciseAssignment? = nil
|
||||
@State private var itemToDelete: SplitExerciseAssignment? = nil
|
||||
|
||||
|
||||
var body: some View {
|
||||
Section(header: Text("Name")) {
|
||||
TextField("Name", text: $model.name)
|
||||
@ -62,37 +65,80 @@ fileprivate struct SplitFormView: View {
|
||||
}
|
||||
|
||||
Section(header: Text("Exercises")) {
|
||||
if let assignments = model.exercises, !assignments.isEmpty {
|
||||
ForEach(assignments) { item in
|
||||
ListItem(
|
||||
title: item.exercise?.name ?? Exercise.unnamed,
|
||||
subtitle: "\(item.sets) × \(item.reps) @ \(item.weight) lbs"
|
||||
)
|
||||
.swipeActions {
|
||||
Button(role: .destructive) {
|
||||
itemToDelete = item
|
||||
} label: {
|
||||
Label("Delete", systemImage: "trash")
|
||||
NavigationLink {
|
||||
NavigationStack {
|
||||
Form {
|
||||
List {
|
||||
if let assignments = model.exercises, !assignments.isEmpty {
|
||||
let sortedAssignments = assignments.sorted(by: { $0.order == $1.order ? $0.exercise?.name ?? Exercise.unnamed < $1.exercise?.name ?? Exercise.unnamed : $0.order < $1.order })
|
||||
ForEach(sortedAssignments) { item in
|
||||
ListItem(
|
||||
title: item.exercise?.name ?? Exercise.unnamed,
|
||||
subtitle: "\(item.sets) × \(item.reps) × \(item.weight) lbs"
|
||||
)
|
||||
.swipeActions {
|
||||
Button(role: .destructive) {
|
||||
itemToDelete = item
|
||||
} label: {
|
||||
Label("Delete", systemImage: "trash")
|
||||
}
|
||||
Button {
|
||||
itemToEdit = item
|
||||
} label: {
|
||||
Label("Edit", systemImage: "pencil")
|
||||
}
|
||||
.tint(.indigo)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Text("No exercises added yet.")
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationTitle("Exercises")
|
||||
}
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
Button(action: { showingAddSheet.toggle() }) {
|
||||
Image(systemName: "plus")
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Text("No exercises added yet.")
|
||||
}
|
||||
Button(action: {
|
||||
// TODO: Implement add exercise functionality
|
||||
}) {
|
||||
Label("Add Exercise", systemImage: "plus.circle")
|
||||
}
|
||||
}
|
||||
.confirmationDialog("Delete Exercise?", isPresented: .constant(itemToDelete != nil), titleVisibility: .visible) {
|
||||
Button("Delete", role: .destructive) {
|
||||
if let item = itemToDelete {
|
||||
withAnimation {
|
||||
model.exercises?.removeAll { $0.id == item.id }
|
||||
itemToDelete = nil
|
||||
.sheet (isPresented: $showingAddSheet) {
|
||||
ExercisePickerView { exercise in
|
||||
itemToEdit = SplitExerciseAssignment(
|
||||
order: 0,
|
||||
sets: exercise.sets,
|
||||
reps: exercise.reps,
|
||||
weight: exercise.weight,
|
||||
split: model,
|
||||
exercise: exercise
|
||||
)
|
||||
}
|
||||
}
|
||||
.sheet(item: $itemToEdit) { item in
|
||||
SplitExerciseAssignmentAddEditView(model: item)
|
||||
}
|
||||
.confirmationDialog(
|
||||
"Delete Exercise?",
|
||||
isPresented: .constant(itemToDelete != nil),
|
||||
titleVisibility: .visible
|
||||
) {
|
||||
Button("Delete", role: .destructive) {
|
||||
if let item = itemToDelete {
|
||||
withAnimation {
|
||||
model.exercises?.removeAll { $0.id == item.id }
|
||||
itemToDelete = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} label: {
|
||||
ListItem(
|
||||
text: "Exercises",
|
||||
count: model.exercises?.count ?? 0
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user