clean up ActiveWorkoutSession
This commit is contained in:
@@ -1,117 +0,0 @@
|
||||
//
|
||||
// AddExercise.swift
|
||||
// WorkoutsPlus
|
||||
//
|
||||
// Created by Felix Förtsch on 21.09.24.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import SwiftData
|
||||
|
||||
struct ExerciseEditor: View {
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
var isPresentedAsSheet: Bool = false
|
||||
|
||||
@State var exercise: Exercise?
|
||||
|
||||
@State private var name: String = ""
|
||||
@State private var description: String = ""
|
||||
@State private var metric = ExerciseMetric.none
|
||||
@State private var unit = ExerciseUnit(name: "", symbol: "")
|
||||
|
||||
@State private var isPartOfProgression: Bool = false
|
||||
|
||||
let exerciseUnits = ExerciseUnit.getUnits
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
VStack {
|
||||
ScrollViewReader { proxy in
|
||||
VStack {
|
||||
Form {
|
||||
Section {
|
||||
TextField("Exercise Name", text: $name)
|
||||
// TODO: Add Autocomplete
|
||||
TextEditorWithPlaceholder(text: $description, placeholder: "Description (optional)")
|
||||
}
|
||||
Section(footer: Text("""
|
||||
Examples:
|
||||
• Pull-up → None
|
||||
• Weighted Pull-up → Weight
|
||||
• Sprint → Time or Distance
|
||||
""")) {
|
||||
Picker("Exercise Metric", selection: $metric) {
|
||||
ForEach(ExerciseMetric.allCases) { metric in
|
||||
Text(metric.rawValue.isEmpty ? "None" : metric.rawValue)
|
||||
.tag(metric)
|
||||
}
|
||||
}
|
||||
.pickerStyle(SegmentedPickerStyle())
|
||||
Picker("Select Exercise Unit", selection: $unit) {
|
||||
ForEach(exerciseUnits, id: \.self) { unit in
|
||||
Text("\(unit.name) (\(unit.symbol))").tag(unit as ExerciseUnit?)
|
||||
}
|
||||
}
|
||||
.pickerStyle(NavigationLinkPickerStyle())
|
||||
}
|
||||
Section(footer: Text("Feature coming soon.")) {
|
||||
Toggle(isOn: $isPartOfProgression) {
|
||||
Text("Exercise is Part of a Progression")
|
||||
.foregroundStyle(.gray)
|
||||
}
|
||||
.disabled(true)
|
||||
}
|
||||
}
|
||||
.navigationTitle("Edit")
|
||||
.toolbar {
|
||||
if isPresentedAsSheet {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button("Cancel", role: .cancel) {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
Button("Save") {
|
||||
withAnimation {
|
||||
save()
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
if let exercise {
|
||||
self.name = exercise.name
|
||||
self.description = exercise.exerciseDescription
|
||||
self.metric = exercise.metric
|
||||
self.isPartOfProgression = exercise.isPartOfProgression
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func save() {
|
||||
let exerciseToSave: Exercise
|
||||
|
||||
if let exercise = exercise {
|
||||
exerciseToSave = exercise
|
||||
} else {
|
||||
exerciseToSave = Exercise(name)
|
||||
modelContext.insert(exerciseToSave)
|
||||
}
|
||||
|
||||
exerciseToSave.name = name
|
||||
exerciseToSave.exerciseDescription = description
|
||||
exerciseToSave.metric = metric
|
||||
exerciseToSave.isPartOfProgression = isPartOfProgression
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
ExerciseEditor()
|
||||
}
|
||||
Reference in New Issue
Block a user