add ModelContainerPreview conecept, move SampleData, fix Exercise, ExerciseUnit, ExerciseType

This commit is contained in:
Felix Förtsch
2024-11-13 13:59:39 +01:00
parent 370e070fcd
commit 02e2937094
11 changed files with 211 additions and 63 deletions
@@ -17,8 +17,8 @@ struct AddExercise: View {
@State private var name: String = ""
@State private var description: String = ""
@State private var type = ExerciseType("")
@State private var unit = ExerciseUnit("", symbol: "")
@State private var type: ExerciseType?
@State private var unit: ExerciseUnit?
@State private var isPartOfProgression: Bool = false
@@ -41,12 +41,14 @@ struct AddExercise: View {
• Sprint → Time or Distance
""")) {
Picker("Exercise Type", selection: $type) {
Text("None").tag(nil as ExerciseType?)
ForEach(exerciseTypes, id: \.self) { type in
Text("\(type.name)").tag(type as ExerciseType?)
}
}
.pickerStyle(NavigationLinkPickerStyle())
Picker("Exercise Unit", selection: $unit) {
Text("None").tag(nil as ExerciseUnit?)
ForEach(exerciseUnits, id: \.self) { unit in
Text("\(unit.name) (\(unit.symbol))").tag(unit as ExerciseUnit?)
}
@@ -66,7 +68,7 @@ struct AddExercise: View {
ToolbarItem(placement: .confirmationAction) {
Button("Save") {
withAnimation {
save()
saveNew()
dismiss()
}
}
@@ -76,7 +78,7 @@ struct AddExercise: View {
}
}
private func save() {
private func saveNew() {
let exerciseToSave = Exercise(name)
modelContext.insert(exerciseToSave)