Files
workouts/Workouts/Views/Exercises/ExerciseAddEditView.swift
2025-07-25 17:42:25 -04:00

79 lines
2.6 KiB
Swift
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// SplitExerciseAssignment.swift
// Workouts
//
// Created by rzen on 7/15/25 at 7:12AM.
//
// Copyright 2025 Rouslan Zenetl. All Rights Reserved.
//
import SwiftUI
struct ExerciseAddEditView: View {
@Environment(\.modelContext) private var modelContext
@Environment(\.dismiss) private var dismiss
@State private var showingExercisePicker = false
@State var model: Exercise
var body: some View {
NavigationStack {
Form {
Section(header: Text("Exercise")) {
Button(action: {
showingExercisePicker = true
}) {
HStack {
Text(model.name.isEmpty ? "Select Exercise" : model.name)
Spacer()
Image(systemName: "chevron.right")
.foregroundColor(.gray)
}
}
}
Section (header: Text("Sets/Reps")) {
Stepper("Sets: \(model.sets)", value: $model.sets, in: 1...10)
Stepper("Reps: \(model.reps)", value: $model.reps, in: 1...50)
}
// Weight section
Section (header: Text("Weight")) {
HStack {
VStack(alignment: .center) {
Text("\(model.weight) lbs")
.font(.headline)
}
Spacer()
VStack(alignment: .trailing) {
Stepper("±1", value: $model.weight, in: 0...1000)
Stepper("±5", value: $model.weight, in: 0...1000, step: 5)
}
.frame(width: 130)
}
}
}
.sheet(isPresented: $showingExercisePicker) {
ExercisePickerView { exerciseNames in
model.name = exerciseNames.first ?? "Exercise.unnamed"
}
}
.navigationTitle(model.name.isEmpty ? "New Exercise" : model.name)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button("Cancel") {
dismiss()
}
}
ToolbarItem(placement: .navigationBarTrailing) {
Button("Save") {
try? modelContext.save()
dismiss()
}
}
}
}
}
}