79 lines
2.9 KiB
Swift
79 lines
2.9 KiB
Swift
import SwiftUI
|
||
|
||
struct SplitAddEditView: View {
|
||
@Environment(\.dismiss) private var dismiss
|
||
@Environment(\.modelContext) private var modelContext
|
||
|
||
@Bindable var model: Split
|
||
|
||
@State var itemToEdit: SplitExerciseAssignment? = nil
|
||
@State var itemToDelete: SplitExerciseAssignment? = nil
|
||
|
||
var body: some View {
|
||
NavigationStack {
|
||
Form {
|
||
Section (header: Text("Name")) {
|
||
TextField("Name", text: $model.name)
|
||
.bold()
|
||
}
|
||
|
||
Section(header: Text("Description")) {
|
||
TextEditor(text: $model.intro)
|
||
.frame(minHeight: 100)
|
||
.padding(.vertical, 4)
|
||
}
|
||
|
||
Section(header: Text("Exercises")) {
|
||
let item = model
|
||
if let assignments = item.exercises, !assignments.isEmpty {
|
||
ForEach(assignments, id: \.id) { item in
|
||
List {
|
||
ListItem(
|
||
title: item.exercise?.name ?? "Unnamed",
|
||
subtitle: "\(item.sets) × \(item.reps) @ \(item.weight) lbs"
|
||
)
|
||
.swipeActions(edge: .trailing, allowsFullSwipe: false) {
|
||
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")
|
||
.foregroundColor(.secondary)
|
||
}
|
||
|
||
Button(action: {
|
||
|
||
}) {
|
||
Label("Add Exercise", systemImage: "plus.circle")
|
||
}
|
||
}
|
||
}
|
||
.toolbar {
|
||
ToolbarItem(placement: .navigationBarLeading) {
|
||
Button("Cancel") {
|
||
dismiss()
|
||
}
|
||
}
|
||
|
||
ToolbarItem(placement: .navigationBarTrailing) {
|
||
Button("Save") {
|
||
try? modelContext.save()
|
||
dismiss()
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|