WIP
This commit is contained in:
@@ -84,6 +84,7 @@ struct CreateExerciseActionsView: View {
|
||||
|
||||
Button(action: {
|
||||
superset.deleteExerciseForChosenSuperset(exercise: workoutExercise)
|
||||
viewModel.increaseRandomNumberForUpdating()
|
||||
viewModel.objectWillChange.send()
|
||||
}) {
|
||||
Image(systemName: "trash.fill")
|
||||
|
||||
@@ -56,7 +56,11 @@ class CreateWorkoutExercise: ObservableObject, Identifiable {
|
||||
}
|
||||
}
|
||||
|
||||
class CreateWorkoutSuperSet: ObservableObject, Identifiable {
|
||||
class CreateWorkoutSuperSet: ObservableObject, Identifiable, Equatable {
|
||||
static func == (lhs: CreateWorkoutSuperSet, rhs: CreateWorkoutSuperSet) -> Bool {
|
||||
lhs.id == rhs.id
|
||||
}
|
||||
|
||||
let id = UUID()
|
||||
@Published var exercises = [CreateWorkoutExercise]()
|
||||
@Published var numberOfRounds = 0
|
||||
@@ -85,8 +89,14 @@ class WorkoutViewModel: ObservableObject {
|
||||
@Published var superSets = [CreateWorkoutSuperSet]()
|
||||
@Published var title = String()
|
||||
@Published var description = String()
|
||||
@Published var randomValueForUpdatingValue = 0
|
||||
|
||||
func increaseRandomNumberForUpdating() {
|
||||
randomValueForUpdatingValue += 1
|
||||
}
|
||||
|
||||
func addNewSuperset() {
|
||||
increaseRandomNumberForUpdating()
|
||||
superSets.append(CreateWorkoutSuperSet())
|
||||
}
|
||||
|
||||
@@ -95,6 +105,7 @@ class WorkoutViewModel: ObservableObject {
|
||||
$0.id == superset.id
|
||||
}) {
|
||||
superSets.remove(at: idx)
|
||||
increaseRandomNumberForUpdating()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,49 +24,61 @@ struct CreateWorkoutMainView: View {
|
||||
.padding()
|
||||
.frame(height: 55)
|
||||
.textFieldStyle(OvalTextFieldStyle())
|
||||
|
||||
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.count > 0 {
|
||||
Text(exercise.wrappedValue.exercise.side)
|
||||
.font(.title3)
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
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.count > 0 {
|
||||
Text(exercise.wrappedValue.exercise.side)
|
||||
.font(.title3)
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
}
|
||||
CreateExerciseActionsView(workoutExercise: exercise.wrappedValue,
|
||||
superset: superset.wrappedValue,
|
||||
viewModel: viewModel)
|
||||
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
HStack {
|
||||
Stepper("Number of rounds", onIncrement: {
|
||||
superset.wrappedValue.increaseNumberOfRounds()
|
||||
viewModel.objectWillChange.send()
|
||||
}, onDecrement: {
|
||||
superset.wrappedValue.decreaseNumberOfRounds()
|
||||
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)
|
||||
}
|
||||
Text("this is the bottom 🤷♂️")
|
||||
.id(999)
|
||||
|
||||
.listRowSeparator(.hidden)
|
||||
}
|
||||
.listRowSeparator(.hidden)
|
||||
.onChange(of: viewModel.randomValueForUpdatingValue, perform: { newValue in
|
||||
withAnimation {
|
||||
proxy.scrollTo(999, anchor: .bottom)
|
||||
}
|
||||
})
|
||||
}
|
||||
// .overlay(Group {
|
||||
// if($viewModel.superSets.isEmpty) {
|
||||
@@ -137,6 +149,7 @@ struct CreateWorkoutMainView: View {
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.increaseRandomNumberForUpdating()
|
||||
viewModel.objectWillChange.send()
|
||||
selectedCreateWorkoutSuperSet = nil
|
||||
})
|
||||
|
||||
@@ -30,6 +30,7 @@ struct CreateWorkoutSupersetActionsView: View {
|
||||
|
||||
Button(action: {
|
||||
viewModel.delete(superset: workoutSuperSet)
|
||||
viewModel.increaseRandomNumberForUpdating()
|
||||
viewModel.objectWillChange.send()
|
||||
|
||||
}) {
|
||||
|
||||
Reference in New Issue
Block a user