This commit is contained in:
Trey t
2023-07-17 23:33:18 -05:00
parent af538362e8
commit 2753e31f24
8 changed files with 85 additions and 27 deletions

View File

@@ -12,7 +12,8 @@ struct AccountView: View {
@State var completedWorkouts: [CompletedWorkout]? @State var completedWorkouts: [CompletedWorkout]?
@ObservedObject var userStore = UserStore.shared @ObservedObject var userStore = UserStore.shared
@State var showCompletedWorkouts: Bool = false @State var showCompletedWorkouts: Bool = false
@AppStorage("thotStyle") private var thotStyle: ThotStyle = .never @AppStorage(Constants.phoneThotStyle) private var phoneThotStyle: ThotStyle = .never
@AppStorage(Constants.extThotStyle) private var extThotStyle: ThotStyle = .never
var body: some View { var body: some View {
VStack(alignment: .leading) { VStack(alignment: .leading) {
@@ -62,11 +63,22 @@ struct AccountView: View {
} }
} }
Divider() Divider()
Text("Phone THOT Style:")
Picker("THOT Style:", selection: $thotStyle) { Picker("Phone THOT Style:", selection: $phoneThotStyle) {
ForEach(ThotStyle.allCases, id: \.self) { style in ForEach(ThotStyle.allCases, id: \.self) { style in
Text(style.stringValue()) Text(style.stringValue())
.tag(thotStyle.rawValue) .tag(phoneThotStyle.rawValue)
}
}
.pickerStyle(.segmented)
Divider()
Text("External THOT Style:")
Picker("External THOT Style:", selection: $extThotStyle) {
ForEach(ThotStyle.allCases, id: \.self) { style in
Text(style.stringValue())
.tag(extThotStyle.rawValue)
} }
} }
.pickerStyle(.segmented) .pickerStyle(.segmented)

View File

@@ -19,6 +19,8 @@ struct CreateExerciseActionsView: View {
VStack { VStack {
Text("Reps: ") Text("Reps: ")
Text("\(workoutExercise.reps)") Text("\(workoutExercise.reps)")
.foregroundColor(workoutExercise.reps == 0 && workoutExercise.duration == 0 ? .red : Color(uiColor: .label))
.bold()
} }
Stepper("", onIncrement: { Stepper("", onIncrement: {
workoutExercise.increaseReps() workoutExercise.increaseReps()
@@ -51,6 +53,8 @@ struct CreateExerciseActionsView: View {
VStack { VStack {
Text("Duration: ") Text("Duration: ")
Text("\(workoutExercise.duration)") Text("\(workoutExercise.duration)")
.foregroundColor(workoutExercise.reps == 0 && workoutExercise.duration == 0 ? .red : Color(uiColor: .label))
.bold()
} }
Stepper("", onIncrement: { Stepper("", onIncrement: {
workoutExercise.increaseDuration() workoutExercise.increaseDuration()

View File

@@ -107,32 +107,42 @@ class WorkoutViewModel: ObservableObject {
} }
func uploadWorkout() { func uploadWorkout() {
var exercises = [[String: Any]]() var supersets = [[String: Any]]()
var supersetOrder = 1
superSets.forEach({ superset in superSets.forEach({ superset in
if superset.numberOfRounds == 0 { if superset.numberOfRounds == 0 {
showRoundsError() showRoundsError()
return return
} }
var supersetInfo = [String: Any]()
supersetInfo["name"] = ""
supersetInfo["rounds"] = superset.numberOfRounds
supersetInfo["order"] = supersetOrder
for _ in 0 ..< superset.numberOfRounds { var exercises = [[String: Any]]()
for exercise in superset.exercises { var exerciseOrder = 1
for exercise in superset.exercises {
if exercise.reps == 0 && exercise.duration == 0 { if exercise.reps == 0 && exercise.duration == 0 {
showNoDurationOrReps() showNoDurationOrReps()
return return
}
let item = ["id": exercise.exercise.id,
"reps": exercise.reps,
"weight": exercise.weight,
"duration": exercise.duration] as [String : Any]
exercises.append(item)
} }
let item = ["id": exercise.exercise.id,
"reps": exercise.reps,
"weight": exercise.weight,
"duration": exercise.duration,
"order": exerciseOrder] as [String : Any]
exercises.append(item)
exerciseOrder += 1
} }
supersetInfo["exercises"] = exercises
supersets.append(supersetInfo)
supersetOrder += 1
}) })
let uploadBody = ["name": title, let uploadBody = ["name": title,
"description": description, "description": description,
"exercise_data": exercises] as [String : Any] "supersets": supersets] as [String : Any]
CreateWorkoutFetchable(postData: uploadBody).fetch(completion: { result in CreateWorkoutFetchable(postData: uploadBody).fetch(completion: { result in
DispatchQueue.main.async { DispatchQueue.main.async {
switch result { switch result {

View File

@@ -47,7 +47,6 @@ struct CreateWorkoutMainView: View {
} }
} }
HStack { HStack {
Stepper("Number of rounds", onIncrement: { Stepper("Number of rounds", onIncrement: {
superset.wrappedValue.increaseNumberOfRounds() superset.wrappedValue.increaseNumberOfRounds()
@@ -58,6 +57,7 @@ struct CreateWorkoutMainView: View {
}) })
Text("\(superset.wrappedValue.numberOfRounds)") Text("\(superset.wrappedValue.numberOfRounds)")
.foregroundColor(superset.numberOfRounds.wrappedValue > 0 ? .black : .red) .foregroundColor(superset.numberOfRounds.wrappedValue > 0 ? .black : .red)
.bold()
} }
CreateWorkoutSupersetActionsView(workoutSuperSet: superset.wrappedValue, CreateWorkoutSupersetActionsView(workoutSuperSet: superset.wrappedValue,
@@ -111,6 +111,32 @@ struct CreateWorkoutMainView: View {
AddExerciseView(selectedExercise: { exercise in AddExerciseView(selectedExercise: { exercise in
let workoutExercise = CreateWorkoutExercise(exercise: exercise) let workoutExercise = CreateWorkoutExercise(exercise: exercise)
selectedCreateWorkoutSuperSet?.exercises.append(workoutExercise) 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.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.objectWillChange.send() viewModel.objectWillChange.send()
selectedCreateWorkoutSuperSet = nil selectedCreateWorkoutSuperSet = nil
}) })

View File

@@ -11,7 +11,7 @@ import AVKit
struct ExternalWorkoutDetailView: View { struct ExternalWorkoutDetailView: View {
@StateObject var bridgeModule = BridgeModule.shared @StateObject var bridgeModule = BridgeModule.shared
@State var avPlayer = AVPlayer(url: URL(string: "https://dev.werkout.fitness/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4")!) @State var avPlayer = AVPlayer(url: URL(string: "https://dev.werkout.fitness/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4")!)
@AppStorage("thotStyle") private var thotStyle: ThotStyle = .never @AppStorage(Constants.extThotStyle) private var extThotStyle: ThotStyle = .never
var body: some View { var body: some View {
ZStack { ZStack {
@@ -57,7 +57,7 @@ struct ExternalWorkoutDetailView: View {
.onChange(of: bridgeModule.currentExerciseInfo.exerciseIndex, perform: { newValue in .onChange(of: bridgeModule.currentExerciseInfo.exerciseIndex, perform: { newValue in
if let currentExtercise = bridgeModule.currentExerciseInfo.currentExercise { if let currentExtercise = bridgeModule.currentExerciseInfo.currentExercise {
if let videoURL = VideoURLCreator.videoURL( if let videoURL = VideoURLCreator.videoURL(
thotStyle: thotStyle, thotStyle: extThotStyle,
defaultVideoURLStr: currentExtercise.exercise.videoURL, defaultVideoURLStr: currentExtercise.exercise.videoURL,
exerciseName: currentExtercise.exercise.name, exerciseName: currentExtercise.exercise.name,
workout: bridgeModule.currentExerciseInfo.workout) { workout: bridgeModule.currentExerciseInfo.workout) {

View File

@@ -9,7 +9,7 @@ import SwiftUI
import AVKit import AVKit
struct ExerciseListView: View { struct ExerciseListView: View {
@AppStorage("thotStyle") private var thotStyle: ThotStyle = .never @AppStorage(Constants.phoneThotStyle) private var phoneThotStyle: ThotStyle = .never
@ObservedObject var bridgeModule = BridgeModule.shared @ObservedObject var bridgeModule = BridgeModule.shared
@State var avPlayer = AVPlayer(url: URL(string: "https://dev.werkout.fitness/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4")!) @State var avPlayer = AVPlayer(url: URL(string: "https://dev.werkout.fitness/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4")!)
var workout: Workout var workout: Workout
@@ -17,7 +17,7 @@ struct ExerciseListView: View {
@State var videoExercise: Exercise? { @State var videoExercise: Exercise? {
didSet { didSet {
if let videoURL = VideoURLCreator.videoURL( if let videoURL = VideoURLCreator.videoURL(
thotStyle: thotStyle, thotStyle: phoneThotStyle,
defaultVideoURLStr: self.videoExercise?.videoURL, defaultVideoURLStr: self.videoExercise?.videoURL,
exerciseName: self.videoExercise?.name, exerciseName: self.videoExercise?.name,
workout: bridgeModule.currentExerciseInfo.workout) { workout: bridgeModule.currentExerciseInfo.workout) {

View File

@@ -14,7 +14,7 @@ struct WorkoutDetailView: View {
@StateObject var bridgeModule = BridgeModule.shared @StateObject var bridgeModule = BridgeModule.shared
@Environment(\.dismiss) var dismiss @Environment(\.dismiss) var dismiss
@AppStorage("thotStyle") private var thotStyle: ThotStyle = .never @AppStorage(Constants.phoneThotStyle) private var phoneThotStyle: ThotStyle = .never
enum Sheet: Identifiable { enum Sheet: Identifiable {
case completedWorkout([String: Any]) case completedWorkout([String: Any])
@@ -103,7 +103,7 @@ struct WorkoutDetailView: View {
.onChange(of: bridgeModule.currentExerciseInfo.exerciseIndex, perform: { newValue in .onChange(of: bridgeModule.currentExerciseInfo.exerciseIndex, perform: { newValue in
if let currentExtercise = bridgeModule.currentExerciseInfo.currentExercise { if let currentExtercise = bridgeModule.currentExerciseInfo.currentExercise {
if let videoURL = VideoURLCreator.videoURL( if let videoURL = VideoURLCreator.videoURL(
thotStyle: thotStyle, thotStyle: phoneThotStyle,
defaultVideoURLStr: currentExtercise.exercise.videoURL, defaultVideoURLStr: currentExtercise.exercise.videoURL,
exerciseName: currentExtercise.exercise.name, exerciseName: currentExtercise.exercise.name,
workout: bridgeModule.currentExerciseInfo.workout) { workout: bridgeModule.currentExerciseInfo.workout) {
@@ -115,7 +115,7 @@ struct WorkoutDetailView: View {
.onAppear{ .onAppear{
if let currentExtercise = bridgeModule.currentExerciseInfo.currentExercise { if let currentExtercise = bridgeModule.currentExerciseInfo.currentExercise {
if let videoURL = VideoURLCreator.videoURL( if let videoURL = VideoURLCreator.videoURL(
thotStyle: thotStyle, thotStyle: phoneThotStyle,
defaultVideoURLStr: currentExtercise.exercise.videoURL, defaultVideoURLStr: currentExtercise.exercise.videoURL,
exerciseName: currentExtercise.exercise.name, exerciseName: currentExtercise.exercise.name,
workout: bridgeModule.currentExerciseInfo.workout) { workout: bridgeModule.currentExerciseInfo.workout) {

View File

@@ -9,6 +9,12 @@ import SwiftUI
import Combine import Combine
import AVKit import AVKit
struct Constants {
static let phoneThotStyle = "phoneThotStyle"
static let extThotStyle = "extThotStyle"
}
@main @main
struct Werkout_iosApp: App { struct Werkout_iosApp: App {
let persistenceController = PersistenceController.shared let persistenceController = PersistenceController.shared