UI changes
This commit is contained in:
@@ -14,54 +14,47 @@ struct CreateExerciseActionsView: View {
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
HStack {
|
||||
VStack {
|
||||
VStack {
|
||||
Text("Reps: ")
|
||||
Text("\(workoutExercise.reps)")
|
||||
.foregroundColor(workoutExercise.reps == 0 && workoutExercise.duration == 0 ? .red : Color(uiColor: .label))
|
||||
.bold()
|
||||
}
|
||||
VStack {
|
||||
HStack {
|
||||
Text("Reps: ")
|
||||
Text("\(workoutExercise.reps)")
|
||||
.foregroundColor(workoutExercise.reps == 0 && workoutExercise.duration == 0 ? .red : Color(uiColor: .label))
|
||||
.bold()
|
||||
|
||||
Stepper("", onIncrement: {
|
||||
workoutExercise.increaseReps()
|
||||
}, onDecrement: {
|
||||
workoutExercise.decreaseReps()
|
||||
})
|
||||
.labelsHidden()
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
|
||||
HStack {
|
||||
Text("Weight: ")
|
||||
Text("\(workoutExercise.weight)")
|
||||
|
||||
Divider()
|
||||
Stepper("", onIncrement: {
|
||||
workoutExercise.increaseWeight()
|
||||
}, onDecrement: {
|
||||
workoutExercise.decreaseWeight()
|
||||
})
|
||||
}
|
||||
|
||||
HStack {
|
||||
Text("Duration: ")
|
||||
Text("\(workoutExercise.duration)")
|
||||
.foregroundColor(
|
||||
workoutExercise.reps == 0 && workoutExercise.duration == 0 ? .red : Color(
|
||||
uiColor: .label
|
||||
)
|
||||
)
|
||||
.bold()
|
||||
|
||||
VStack{
|
||||
VStack {
|
||||
Text("Weight: ")
|
||||
Text("\(workoutExercise.weight)")
|
||||
}
|
||||
Stepper("", onIncrement: {
|
||||
workoutExercise.increaseWeight()
|
||||
}, onDecrement: {
|
||||
workoutExercise.decreaseWeight()
|
||||
})
|
||||
.labelsHidden()
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
|
||||
Divider()
|
||||
|
||||
VStack{
|
||||
VStack {
|
||||
Text("Duration: ")
|
||||
Text("\(workoutExercise.duration)")
|
||||
.foregroundColor(workoutExercise.reps == 0 && workoutExercise.duration == 0 ? .red : Color(uiColor: .label))
|
||||
.bold()
|
||||
}
|
||||
Stepper("", onIncrement: {
|
||||
workoutExercise.increaseDuration()
|
||||
}, onDecrement: {
|
||||
workoutExercise.decreaseDuration()
|
||||
})
|
||||
}
|
||||
Stepper("", onIncrement: {
|
||||
workoutExercise.increaseDuration()
|
||||
}, onDecrement: {
|
||||
workoutExercise.decreaseDuration()
|
||||
})
|
||||
}
|
||||
|
||||
HStack {
|
||||
@@ -73,17 +66,16 @@ struct CreateExerciseActionsView: View {
|
||||
.frame(width: 88, height: 44)
|
||||
.foregroundColor(.white)
|
||||
.background(.blue)
|
||||
.cornerRadius(10)
|
||||
.cornerRadius(Constants.buttonRadius)
|
||||
.buttonStyle(BorderlessButtonStyle())
|
||||
|
||||
Spacer()
|
||||
|
||||
Divider()
|
||||
|
||||
Spacer()
|
||||
|
||||
Button(action: {
|
||||
superset.deleteExerciseForChosenSuperset(exercise: workoutExercise)
|
||||
superset
|
||||
.deleteExerciseForChosenSuperset(exercise: workoutExercise)
|
||||
viewModel.increaseRandomNumberForUpdating()
|
||||
viewModel.objectWillChange.send()
|
||||
}) {
|
||||
@@ -92,14 +84,13 @@ struct CreateExerciseActionsView: View {
|
||||
.frame(width: 88, height: 44)
|
||||
.foregroundColor(.white)
|
||||
.background(.red)
|
||||
.cornerRadius(10)
|
||||
.cornerRadius(Constants.buttonRadius)
|
||||
.buttonStyle(BorderlessButtonStyle())
|
||||
|
||||
Spacer()
|
||||
}
|
||||
|
||||
Divider()
|
||||
.background(.blue)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ class CreateWorkoutSuperSet: ObservableObject, Identifiable, Equatable {
|
||||
}
|
||||
|
||||
let id = UUID()
|
||||
@Published var title: String = ""
|
||||
@Published var exercises = [CreateWorkoutExercise]()
|
||||
@Published var numberOfRounds = 0
|
||||
|
||||
|
||||
@@ -79,7 +79,7 @@ struct CreateWorkoutItemPickerView: View {
|
||||
.frame(height: 44)
|
||||
.foregroundColor(.green)
|
||||
.background(.white)
|
||||
.cornerRadius(8)
|
||||
.cornerRadius(Constants.buttonRadius)
|
||||
.padding()
|
||||
|
||||
Button(action: {
|
||||
@@ -92,7 +92,7 @@ struct CreateWorkoutItemPickerView: View {
|
||||
.frame(height: 44)
|
||||
.foregroundColor(.blue)
|
||||
.background(.yellow)
|
||||
.cornerRadius(8)
|
||||
.cornerRadius(Constants.buttonRadius)
|
||||
.padding()
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
|
||||
@@ -8,71 +8,39 @@
|
||||
import SwiftUI
|
||||
|
||||
struct CreateWorkoutMainView: View {
|
||||
@ObservedObject var viewModel = WorkoutViewModel()
|
||||
@State private var showAddExercise = false
|
||||
@StateObject var viewModel = WorkoutViewModel()
|
||||
@State var selectedCreateWorkoutSuperSet: CreateWorkoutSuperSet?
|
||||
@State private var showAddExercise = false
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
VStack {
|
||||
TextField("Title", text: $viewModel.title)
|
||||
.padding(.horizontal)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
|
||||
TextField("Description", text: $viewModel.description)
|
||||
.padding(.horizontal)
|
||||
.textFieldStyle(.roundedBorder)
|
||||
}
|
||||
.padding(.bottom)
|
||||
.background(Color(uiColor: .systemGray5))
|
||||
|
||||
TextField("Title", text: $viewModel.title)
|
||||
.padding()
|
||||
.frame(height: 55)
|
||||
.textFieldStyle(OvalTextFieldStyle())
|
||||
|
||||
TextField("Description", text: $viewModel.description)
|
||||
.padding()
|
||||
.frame(height: 55)
|
||||
.textFieldStyle(OvalTextFieldStyle())
|
||||
ScrollViewReader { proxy in
|
||||
List() {
|
||||
ForEach($viewModel.superSets, id: \.id) { superset in
|
||||
Section {
|
||||
ForEach(superset.exercises, id: \.id) { exercise in
|
||||
HStack {
|
||||
VStack {
|
||||
Text(exercise.wrappedValue.exercise.name)
|
||||
.font(.title2)
|
||||
.frame(maxWidth: .infinity)
|
||||
if exercise.wrappedValue.exercise.side != nil && exercise.wrappedValue.exercise.side!.count > 0 {
|
||||
Text(exercise.wrappedValue.exercise.side!)
|
||||
.font(.title3)
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
}
|
||||
CreateExerciseActionsView(workoutExercise: exercise.wrappedValue,
|
||||
superset: superset.wrappedValue,
|
||||
viewModel: viewModel)
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
HStack {
|
||||
Stepper("Number of rounds", onIncrement: {
|
||||
superset.wrappedValue.increaseNumberOfRounds()
|
||||
viewModel.increaseRandomNumberForUpdating()
|
||||
viewModel.objectWillChange.send()
|
||||
}, onDecrement: {
|
||||
superset.wrappedValue.decreaseNumberOfRounds()
|
||||
viewModel.increaseRandomNumberForUpdating()
|
||||
viewModel.objectWillChange.send()
|
||||
})
|
||||
|
||||
Text("\(superset.wrappedValue.numberOfRounds)")
|
||||
.foregroundColor(superset.numberOfRounds.wrappedValue > 0 ? .black : .red)
|
||||
.bold()
|
||||
}
|
||||
|
||||
CreateWorkoutSupersetActionsView(workoutSuperSet: superset.wrappedValue,
|
||||
showAddExercise: $showAddExercise,
|
||||
viewModel: viewModel,
|
||||
selectedCreateWorkoutSuperSet: $selectedCreateWorkoutSuperSet)
|
||||
}
|
||||
CreateWorkoutSupersetView(
|
||||
selectedCreateWorkoutSuperSet: $selectedCreateWorkoutSuperSet,
|
||||
showAddExercise: $showAddExercise,
|
||||
superset: superset,
|
||||
viewModel: viewModel)
|
||||
}
|
||||
// after adding new exercise we have to scroll to the bottom
|
||||
// where the new exercise is sooo keep this so we can scroll
|
||||
// to id 999
|
||||
Text("this is the bottom 🤷♂️")
|
||||
.id(999)
|
||||
|
||||
.listRowSeparator(.hidden)
|
||||
.listRowSeparator(.hidden)
|
||||
}
|
||||
.onChange(of: viewModel.randomValueForUpdatingValue, perform: { newValue in
|
||||
withAnimation {
|
||||
@@ -80,15 +48,41 @@ struct CreateWorkoutMainView: View {
|
||||
}
|
||||
})
|
||||
}
|
||||
// .overlay(Group {
|
||||
// if($viewModel.superSets.isEmpty) {
|
||||
// ZStack() {
|
||||
// Color(uiColor: .secondarySystemBackground)
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
|
||||
Divider()
|
||||
.sheet(isPresented: $showAddExercise) {
|
||||
AddExerciseView(selectedExercise: { exercise in
|
||||
let workoutExercise = CreateWorkoutExercise(exercise: exercise)
|
||||
selectedCreateWorkoutSuperSet?.exercises.append(workoutExercise)
|
||||
|
||||
|
||||
// if left or right auto add the other side
|
||||
// with a recover in between b/c its
|
||||
// eaiser to delete a recover than add one
|
||||
if exercise.side != nil && exercise.side!.count > 0 {
|
||||
let exercises = DataStore.shared.allExercise?.filter({
|
||||
$0.name == exercise.name
|
||||
})
|
||||
let recover = DataStore.shared.allExercise?.first(where: {
|
||||
$0.name.lowercased() == "recover"
|
||||
})
|
||||
if let exercises = exercises, let recover = recover {
|
||||
if exercises.count == 2 {
|
||||
let recoverWorkoutExercise = CreateWorkoutExercise(exercise: recover)
|
||||
selectedCreateWorkoutSuperSet?.exercises.append(recoverWorkoutExercise)
|
||||
for LRExercise in exercises {
|
||||
if LRExercise.id != exercise.id {
|
||||
let otherSideExercise = CreateWorkoutExercise(exercise: LRExercise)
|
||||
selectedCreateWorkoutSuperSet?.exercises.append(otherSideExercise)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.increaseRandomNumberForUpdating()
|
||||
viewModel.objectWillChange.send()
|
||||
selectedCreateWorkoutSuperSet = nil
|
||||
})
|
||||
}
|
||||
|
||||
HStack {
|
||||
Button("Add Superset", action: {
|
||||
@@ -96,9 +90,9 @@ struct CreateWorkoutMainView: View {
|
||||
})
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.frame(height: 44)
|
||||
.foregroundColor(.blue)
|
||||
.background(.yellow)
|
||||
.cornerRadius(8)
|
||||
.foregroundColor(.white)
|
||||
.background(.blue)
|
||||
.cornerRadius(Constants.buttonRadius)
|
||||
.padding()
|
||||
.frame(maxWidth: .infinity)
|
||||
|
||||
@@ -110,50 +104,17 @@ struct CreateWorkoutMainView: View {
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.frame(height: 44)
|
||||
.foregroundColor(.white)
|
||||
.background(.blue)
|
||||
.cornerRadius(8)
|
||||
.background(.green)
|
||||
.cornerRadius(Constants.buttonRadius)
|
||||
.padding()
|
||||
.frame(maxWidth: .infinity)
|
||||
.disabled(viewModel.title.isEmpty)
|
||||
}
|
||||
.frame(height: 44)
|
||||
.padding(.bottom)
|
||||
}
|
||||
.sheet(isPresented: $showAddExercise) {
|
||||
AddExerciseView(selectedExercise: { exercise in
|
||||
let workoutExercise = CreateWorkoutExercise(exercise: exercise)
|
||||
selectedCreateWorkoutSuperSet?.exercises.append(workoutExercise)
|
||||
|
||||
|
||||
// if left or right auto add the other side
|
||||
// with a recover in between b/c its
|
||||
// eaiser to delete a recover than add one
|
||||
if exercise.side != nil && exercise.side!.count > 0 {
|
||||
let exercises = DataStore.shared.allExercise?.filter({
|
||||
$0.name == exercise.name
|
||||
})
|
||||
let recover = DataStore.shared.allExercise?.first(where: {
|
||||
$0.name.lowercased() == "recover"
|
||||
})
|
||||
if let exercises = exercises, let recover = recover {
|
||||
if exercises.count == 2 {
|
||||
let recoverWorkoutExercise = CreateWorkoutExercise(exercise: recover)
|
||||
selectedCreateWorkoutSuperSet?.exercises.append(recoverWorkoutExercise)
|
||||
for LRExercise in exercises {
|
||||
if LRExercise.id != exercise.id {
|
||||
let otherSideExercise = CreateWorkoutExercise(exercise: LRExercise)
|
||||
selectedCreateWorkoutSuperSet?.exercises.append(otherSideExercise)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.increaseRandomNumberForUpdating()
|
||||
viewModel.objectWillChange.send()
|
||||
selectedCreateWorkoutSuperSet = nil
|
||||
})
|
||||
|
||||
Divider()
|
||||
}
|
||||
.background(Color(uiColor: .systemGray5))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,14 +24,12 @@ struct CreateWorkoutSupersetActionsView: View {
|
||||
}
|
||||
.foregroundColor(.white)
|
||||
.background(.green)
|
||||
.cornerRadius(10)
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.buttonStyle(BorderlessButtonStyle())
|
||||
|
||||
Button(action: {
|
||||
viewModel.delete(superset: workoutSuperSet)
|
||||
viewModel.increaseRandomNumberForUpdating()
|
||||
viewModel.objectWillChange.send()
|
||||
// viewModel.delete(superset: workoutSuperSet)
|
||||
// viewModel.increaseRandomNumberForUpdating()
|
||||
// viewModel.objectWillChange.send()
|
||||
|
||||
}) {
|
||||
Text("Delete superset")
|
||||
@@ -39,9 +37,7 @@ struct CreateWorkoutSupersetActionsView: View {
|
||||
}
|
||||
.foregroundColor(.white)
|
||||
.background(.red)
|
||||
.cornerRadius(10)
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
.buttonStyle(BorderlessButtonStyle())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user