97 lines
3.4 KiB
Swift
97 lines
3.4 KiB
Swift
|
|
import SwiftUI
|
|
import SwiftData
|
|
|
|
struct ExerciseAddEditView: View {
|
|
@Environment(\.dismiss) private var dismiss
|
|
@Environment(\.modelContext) private var modelContext
|
|
|
|
@Query(sort: [SortDescriptor(\ExerciseType.name)]) var exerciseTypes: [ExerciseType]
|
|
|
|
@State var model: Exercise
|
|
|
|
init(model: Exercise? = nil) {
|
|
_model = State(initialValue: model ?? Exercise(name: "", setup: "", descr: "", sets: 3, reps: 10, weight: 30))
|
|
}
|
|
|
|
var body: some View {
|
|
Form {
|
|
Section (header: Text("Name")) {
|
|
TextField("Name", text: $model.name)
|
|
.bold()
|
|
}
|
|
|
|
Section (header: Text("Exercise Type")) {
|
|
Picker("Type", selection: $model.type) {
|
|
Text("Select a type").tag(nil as ExerciseType?)
|
|
ForEach(exerciseTypes) { type in
|
|
Text(type.name).tag(type as ExerciseType?)
|
|
}
|
|
}
|
|
}
|
|
|
|
Section(header: Text("Description")) {
|
|
TextEditor(text: $model.descr)
|
|
.frame(minHeight: 100)
|
|
.padding(.vertical, 4)
|
|
}
|
|
|
|
|
|
Section (header: Text("Setup")) {
|
|
TextEditor(text: $model.setup)
|
|
.frame(minHeight: 100)
|
|
.padding(.vertical, 4)
|
|
// } footer: {
|
|
// Text("Describe concisely how equipment should be configured")
|
|
}
|
|
|
|
Section (header: Text("Weight")) {
|
|
HStack {
|
|
Text("\(model.weight)")
|
|
.bold()
|
|
Text("lbs")
|
|
Spacer()
|
|
Stepper("", value: $model.weight, in: 0...1000)
|
|
}
|
|
}
|
|
|
|
|
|
// Section(header: Text("Target Muscles")) {
|
|
// Button(action: {
|
|
// showingMuscleSelection = true
|
|
// }) {
|
|
// HStack {
|
|
// if selectedMuscles.isEmpty {
|
|
// Text("None selected")
|
|
// .foregroundColor(.secondary)
|
|
// } else {
|
|
// Text(selectedMuscles.map { $0.name }.joined(separator: ", "))
|
|
// .foregroundColor(.primary)
|
|
// .multilineTextAlignment(.leading)
|
|
// }
|
|
// Spacer()
|
|
// Image(systemName: "chevron.right")
|
|
// .foregroundColor(.secondary)
|
|
// .font(.caption)
|
|
// }
|
|
// }
|
|
// }
|
|
}
|
|
.toolbar {
|
|
ToolbarItem(placement: .navigationBarLeading) {
|
|
Button("Cancel") {
|
|
dismiss()
|
|
}
|
|
}
|
|
|
|
ToolbarItem(placement: .navigationBarTrailing) {
|
|
Button("Save") {
|
|
try? modelContext.save()
|
|
dismiss()
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|