wip
This commit is contained in:
@ -17,7 +17,17 @@ struct ExerciseAddEditView: View {
|
||||
@State var model: Exercise
|
||||
|
||||
@State var originalWeight: Int? = nil
|
||||
@State var loadType: LoadType = .none
|
||||
|
||||
@State private var minutes = 0
|
||||
@State private var seconds = 0
|
||||
|
||||
@State private var weight_tens = 0
|
||||
@State private var weight = 0
|
||||
|
||||
@State private var reps = 0
|
||||
@State private var sets = 0
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
Form {
|
||||
@ -40,23 +50,88 @@ struct ExerciseAddEditView: View {
|
||||
}
|
||||
|
||||
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)
|
||||
HStack (alignment: .bottom) {
|
||||
VStack (alignment: .center) {
|
||||
Text("Sets")
|
||||
Picker("", selection: $sets) {
|
||||
ForEach(0..<20) { sets in
|
||||
Text("\(sets)").tag(sets)
|
||||
}
|
||||
}
|
||||
.frame(height: 100)
|
||||
.pickerStyle(.wheel)
|
||||
}
|
||||
VStack (alignment: .center) {
|
||||
Text("Reps")
|
||||
Picker("", selection: $reps) {
|
||||
ForEach(0..<100) { reps in
|
||||
Text("\(reps)").tag(reps)
|
||||
}
|
||||
}
|
||||
.frame(height: 100)
|
||||
.pickerStyle(.wheel)
|
||||
}
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
sets = model.sets
|
||||
reps = model.reps
|
||||
}
|
||||
|
||||
// Weight section
|
||||
Section (header: Text("Weight")) {
|
||||
HStack {
|
||||
VStack(alignment: .center) {
|
||||
Text("\(model.weight) lbs")
|
||||
.font(.headline)
|
||||
Section (header: Text("Load Type"), footer: Text("For bodyweight exercises choose None. For resistance or weight training selected Weight. For exercises that are time oriented (like plank or meditation select Time.")) {
|
||||
Picker("", selection: $loadType) {
|
||||
ForEach (LoadType.allCases, id: \.self) { load in
|
||||
Text(load.name)
|
||||
.tag(load)
|
||||
}
|
||||
Spacer()
|
||||
VStack(alignment: .trailing) {
|
||||
Stepper("±1", value: $model.weight, in: 0...1000)
|
||||
Stepper("±5", value: $model.weight, in: 0...1000, step: 5)
|
||||
}
|
||||
.pickerStyle(.segmented)
|
||||
}
|
||||
|
||||
if loadType == .weight {
|
||||
Section (header: Text("Weight")) {
|
||||
HStack {
|
||||
HStack {
|
||||
Picker("", selection: $weight_tens) {
|
||||
ForEach(0..<100) { lbs in
|
||||
Text("\(lbs*10)").tag(lbs*10)
|
||||
}
|
||||
}
|
||||
.frame(height: 100)
|
||||
.pickerStyle(.wheel)
|
||||
|
||||
Picker("", selection: $weight) {
|
||||
ForEach(0..<10) { lbs in
|
||||
Text("\(lbs)").tag(lbs)
|
||||
}
|
||||
}
|
||||
.frame(height: 100)
|
||||
.pickerStyle(.wheel)
|
||||
|
||||
Text("lbs")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if loadType == .duration {
|
||||
Section (header: Text("Duration")) {
|
||||
|
||||
HStack {
|
||||
Picker("Minutes", selection: $minutes) {
|
||||
ForEach(0..<60) { minute in
|
||||
Text("\(minute) min").tag(minute)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.wheel)
|
||||
|
||||
Picker("Seconds", selection: $seconds) {
|
||||
ForEach(0..<60) { second in
|
||||
Text("\(second) sec").tag(second)
|
||||
}
|
||||
}
|
||||
.pickerStyle(.wheel)
|
||||
}
|
||||
.frame(width: 130)
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,6 +148,10 @@ struct ExerciseAddEditView: View {
|
||||
}
|
||||
.onAppear {
|
||||
originalWeight = model.weight
|
||||
weight_tens = model.weight / 10
|
||||
weight = model.weight - weight_tens * 10
|
||||
minutes = Int(model.duration.timeIntervalSince1970) / 60
|
||||
seconds = Int(model.duration.timeIntervalSince1970) - minutes * 60
|
||||
}
|
||||
.sheet(isPresented: $showingExercisePicker) {
|
||||
ExercisePickerView { exerciseNames in
|
||||
@ -94,6 +173,10 @@ struct ExerciseAddEditView: View {
|
||||
model.weightLastUpdated = Date()
|
||||
}
|
||||
}
|
||||
model.duration = Date(timeIntervalSince1970: Double(minutes * 60 + seconds))
|
||||
model.weight = weight_tens + weight
|
||||
model.sets = sets
|
||||
model.reps = reps
|
||||
try? modelContext.save()
|
||||
dismiss()
|
||||
}
|
||||
|
Reference in New Issue
Block a user