79 lines
2.6 KiB
Swift
79 lines
2.6 KiB
Swift
//
|
||
// SplitExerciseAssignment.swift
|
||
// Workouts
|
||
//
|
||
// Created by rzen on 7/15/25 at 7:12 AM.
|
||
//
|
||
// 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()
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|