This commit is contained in:
2025-07-13 21:54:09 -04:00
parent 0545f5dbc7
commit bdaa406876
33 changed files with 984 additions and 714 deletions

View File

@ -1,9 +1,10 @@
import Foundation
import SwiftData
import SwiftUI
@Model
final class Exercise: ListableItem {
@Attribute(.unique) var name: String = ""
final class Exercise {
var name: String = ""
var setup: String = ""
var descr: String = ""
var sets: Int = 0
@ -31,3 +32,62 @@ final class Exercise: ListableItem {
self.weight = weight
}
}
extension Exercise: EditableEntity {
static func createNew() -> Exercise {
return Exercise(name: "", setup: "", descr: "", sets: 3, reps: 10, weight: 30)
}
static var navigationTitle: String {
return "Exercises"
}
@ViewBuilder
static func formView(for model: Exercise) -> some View {
EntityAddEditView(model: model) { $model in
// This internal view is necessary to use @Query within the form.
ExerciseFormView(model: $model)
}
}
}
fileprivate struct ExerciseFormView: View {
@Binding var model: Exercise
@Query(sort: [SortDescriptor(\ExerciseType.name)]) var exerciseTypes: [ExerciseType]
var body: some View {
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)
}
Section(header: Text("Setup")) {
TextEditor(text: $model.setup)
.frame(minHeight: 100)
}
Section(header: Text("Weight")) {
HStack {
Text("\(model.weight)")
.bold()
Text("lbs")
Spacer()
Stepper("", value: $model.weight, in: 0...1000)
}
}
}
}