Fix 28 issues from deep audit and UI audit + redesign changes
Some checks failed
Apple Platform CI / smoke-and-tests (push) Has been cancelled
Some checks failed
Apple Platform CI / smoke-and-tests (push) Has been cancelled
Deep audit (issues 2-14): - Add missing WCSession handlers for applicationContext and userInfo - Fix BoundedFIFOQueue race condition with serial dispatch queue - Fix timer race condition with main thread guarantee - Fix watch pause state divergence — phone is now source of truth - Fix wrong notification posted on logout (createdNewWorkout → userLoggedOut) - Fix POST status check to accept any 2xx (was exact match) - Fix @StateObject → @ObservedObject for injected viewModel - Add pull-to-refresh to CompletedWorkoutsView - Fix typos: RefreshUserInfoFetcable, defualtPackageModle - Replace string concatenation with interpolation - Replace 6 @StateObject with @ObservedObject for BridgeModule.shared - Replace 7 hardcoded AVPlayer URLs with BaseURLs.currentBaseURL UI audit (issues 1-15): - Fix GeometryReader eating VStack space — replaced with .overlay - Fix refreshable continuation resuming before fetch completes - Remove duplicate @State workouts — derive from DataStore - Decouple leaf views from BridgeModule (pass discrete values) - Convert selectedIds from Array to Set for O(1) lookups - Extract .sorted() from var body into computed properties - Move search filter out of ForEach render loop - Replace import SwiftUI with import Combine in non-UI classes - Mark all @State properties private - Extract L/R exercise auto-add logic to WorkoutViewModel - Use enumerated() instead of .indices in ForEach - Make AddSupersetView frame flexible instead of fixed 300pt - Hoist Set construction out of per-exercise filter loop - Move ViewModel network fetch from init to load() Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -8,13 +8,14 @@
|
||||
import SwiftUI
|
||||
|
||||
struct CurrentWorkoutElapsedTimeView: View {
|
||||
@ObservedObject var bridgeModule = BridgeModule.shared
|
||||
|
||||
let currentWorkoutRunTimeInSeconds: Int
|
||||
|
||||
var body: some View {
|
||||
if bridgeModule.currentWorkoutRunTimeInSeconds > -1 {
|
||||
if currentWorkoutRunTimeInSeconds > -1 {
|
||||
VStack {
|
||||
Text("\(Double(bridgeModule.currentWorkoutRunTimeInSeconds).asString(style: .positional))")
|
||||
.font(.title2)
|
||||
Text("\(Double(currentWorkoutRunTimeInSeconds).asString(style: .positional))")
|
||||
.font(.system(size: 20, weight: .black, design: .monospaced))
|
||||
.foregroundStyle(WerkoutTheme.accent)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,138 +10,138 @@ import AVKit
|
||||
|
||||
struct ExerciseListView: View {
|
||||
@AppStorage(Constants.phoneThotStyle) private var phoneThotStyle: ThotStyle = .never
|
||||
@ObservedObject var bridgeModule = BridgeModule.shared
|
||||
@State var avPlayer = AVPlayer(url: URL(string: "https://dev.werkout.fitness/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4") ?? URL(fileURLWithPath: "/dev/null"))
|
||||
@State private var avPlayer = AVPlayer(url: URL(string: BaseURLs.currentBaseURL + "/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4") ?? URL(fileURLWithPath: "/dev/null"))
|
||||
@State private var previewVideoURL: URL?
|
||||
var workout: Workout
|
||||
@Binding var showExecersizeInfo: Bool
|
||||
@AppStorage(Constants.thotGenderOption) private var thotGenderOption: String = "female"
|
||||
|
||||
@State var videoExercise: Exercise? {
|
||||
let isInWorkout: Bool
|
||||
let currentSupersetIndex: Int
|
||||
let currentExerciseIndex: Int
|
||||
let allSupersetExecerciseIndex: Int
|
||||
let currentExercise: SupersetExercise?
|
||||
let currentWorkout: Workout?
|
||||
let goToExerciseAt: (Int, Int) -> Void
|
||||
|
||||
@State private var videoExercise: Exercise? {
|
||||
didSet {
|
||||
if let videoURL = VideoURLCreator.videoURL(
|
||||
thotStyle: phoneThotStyle,
|
||||
gender: thotGenderOption,
|
||||
defaultVideoURLStr: self.videoExercise?.videoURL,
|
||||
exerciseName: self.videoExercise?.name,
|
||||
workout: bridgeModule.currentWorkoutInfo.workout) {
|
||||
workout: currentWorkout) {
|
||||
updatePreviewPlayer(for: videoURL)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var body: some View {
|
||||
let supersets = workout.supersets?.sorted(by: { $0.order < $1.order }) ?? []
|
||||
if supersets.isEmpty == false {
|
||||
ScrollViewReader { proxy in
|
||||
List() {
|
||||
ForEach(supersets.indices, id: \.self) { supersetIndex in
|
||||
let superset = supersets[supersetIndex]
|
||||
ForEach(Array(supersets.enumerated()), id: \.offset) { supersetIndex, superset in
|
||||
Section(content: {
|
||||
ForEach(superset.exercises.indices, id: \.self) { exerciseIndex in
|
||||
let supersetExecercise = superset.exercises[exerciseIndex]
|
||||
ForEach(Array(superset.exercises.enumerated()), id: \.offset) { exerciseIndex, supersetExecercise in
|
||||
let rowID = rowIdentifier(
|
||||
supersetIndex: supersetIndex,
|
||||
exerciseIndex: exerciseIndex,
|
||||
exercise: supersetExecercise
|
||||
)
|
||||
let isCurrentExercise = isInWorkout &&
|
||||
supersetIndex == currentSupersetIndex &&
|
||||
exerciseIndex == currentExerciseIndex
|
||||
|
||||
VStack {
|
||||
Button(action: {
|
||||
if bridgeModule.isInWorkout {
|
||||
bridgeModule.currentWorkoutInfo.goToExerciseAt(
|
||||
supersetIndex: supersetIndex,
|
||||
exerciseIndex: exerciseIndex)
|
||||
if isInWorkout {
|
||||
goToExerciseAt(supersetIndex, exerciseIndex)
|
||||
} else {
|
||||
videoExercise = supersetExecercise.exercise
|
||||
}
|
||||
}, label: {
|
||||
HStack {
|
||||
if bridgeModule.isInWorkout &&
|
||||
supersetIndex == bridgeModule.currentWorkoutInfo.supersetIndex &&
|
||||
exerciseIndex == bridgeModule.currentWorkoutInfo.exerciseIndex {
|
||||
if isCurrentExercise {
|
||||
Image(systemName: "figure.run")
|
||||
.foregroundColor(Color("appColor"))
|
||||
.foregroundStyle(WerkoutTheme.accent)
|
||||
}
|
||||
|
||||
|
||||
Text(supersetExecercise.exercise.extName)
|
||||
|
||||
.foregroundStyle(WerkoutTheme.textPrimary)
|
||||
|
||||
Spacer()
|
||||
|
||||
|
||||
if let reps = supersetExecercise.reps,
|
||||
reps > 0 {
|
||||
HStack {
|
||||
HStack(spacing: 4) {
|
||||
Image(systemName: "number")
|
||||
.foregroundColor(.white)
|
||||
.frame(width: 20, alignment: .leading)
|
||||
Text("\(reps)")
|
||||
.foregroundColor(.white)
|
||||
.frame(width: 30, alignment: .trailing)
|
||||
|
||||
}
|
||||
.padding([.top, .bottom], 5)
|
||||
.padding([.leading], 10)
|
||||
.padding([.trailing], 15)
|
||||
.background(.blue)
|
||||
.cornerRadius(5, corners: [.topLeft, .bottomLeft])
|
||||
.frame(alignment: .trailing)
|
||||
.font(WerkoutTheme.caption)
|
||||
.foregroundStyle(.white)
|
||||
.padding(.horizontal, WerkoutTheme.sm)
|
||||
.padding(.vertical, WerkoutTheme.xs)
|
||||
.background(WerkoutTheme.accent)
|
||||
.clipShape(Capsule())
|
||||
}
|
||||
|
||||
|
||||
if let duration = supersetExecercise.duration,
|
||||
duration > 0 {
|
||||
HStack {
|
||||
HStack(spacing: 4) {
|
||||
Image(systemName: "stopwatch")
|
||||
.foregroundColor(.white)
|
||||
.frame(width: 20, alignment: .leading)
|
||||
Text("\(duration)")
|
||||
.foregroundColor(.white)
|
||||
.frame(width: 30, alignment: .trailing)
|
||||
}
|
||||
.padding([.top, .bottom], 5)
|
||||
.padding([.leading], 10)
|
||||
.padding([.trailing], 15)
|
||||
.background(.green)
|
||||
.cornerRadius(5, corners: [.topLeft, .bottomLeft])
|
||||
.font(WerkoutTheme.caption)
|
||||
.foregroundStyle(.white)
|
||||
.padding(.horizontal, WerkoutTheme.sm)
|
||||
.padding(.vertical, WerkoutTheme.xs)
|
||||
.background(WerkoutTheme.success)
|
||||
.clipShape(Capsule())
|
||||
}
|
||||
}
|
||||
.padding(.trailing, -20)
|
||||
.contentShape(Rectangle())
|
||||
})
|
||||
.buttonStyle(.plain)
|
||||
.accessibilityLabel("Exercise \(supersetExecercise.exercise.extName)")
|
||||
.accessibilityHint(bridgeModule.isInWorkout ? "Jump to this exercise in the workout" : "Preview exercise video")
|
||||
|
||||
if bridgeModule.isInWorkout &&
|
||||
supersetIndex == bridgeModule.currentWorkoutInfo.supersetIndex &&
|
||||
exerciseIndex == bridgeModule.currentWorkoutInfo.exerciseIndex &&
|
||||
showExecersizeInfo {
|
||||
.accessibilityHint(isInWorkout ? "Jump to this exercise in the workout" : "Preview exercise video")
|
||||
|
||||
if isCurrentExercise && showExecersizeInfo {
|
||||
detailView(forExercise: supersetExecercise)
|
||||
}
|
||||
}.id(rowID)
|
||||
}
|
||||
.listRowBackground(
|
||||
isCurrentExercise
|
||||
? WerkoutTheme.accent.opacity(0.1)
|
||||
: WerkoutTheme.surfaceCard
|
||||
)
|
||||
.id(rowID)
|
||||
}
|
||||
}, header: {
|
||||
HStack {
|
||||
Text(superset.name ?? "--")
|
||||
.foregroundColor(Color("appColor"))
|
||||
.bold()
|
||||
.font(WerkoutTheme.sectionTitle)
|
||||
.foregroundStyle(WerkoutTheme.accent)
|
||||
Spacer()
|
||||
Text("\(superset.rounds) rounds")
|
||||
.foregroundColor(Color("appColor"))
|
||||
.bold()
|
||||
|
||||
.font(WerkoutTheme.caption)
|
||||
.foregroundStyle(WerkoutTheme.accent)
|
||||
|
||||
if let estimatedTime = superset.estimatedTime {
|
||||
Text("@ " + estimatedTime.asString(style: .abbreviated))
|
||||
.foregroundColor(Color("appColor"))
|
||||
.bold()
|
||||
.font(WerkoutTheme.caption)
|
||||
.foregroundStyle(WerkoutTheme.accent)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
.onChange(of: bridgeModule.currentWorkoutInfo.allSupersetExecerciseIndex, perform: { newValue in
|
||||
if let newCurrentExercise = bridgeModule.currentWorkoutInfo.currentExercise {
|
||||
.scrollContentBackground(.hidden)
|
||||
.background(WerkoutTheme.background)
|
||||
.onChange(of: allSupersetExecerciseIndex) { _, _ in
|
||||
if let newCurrentExercise = currentExercise {
|
||||
withAnimation {
|
||||
let currentSupersetIndex = bridgeModule.currentWorkoutInfo.supersetIndex
|
||||
let currentExerciseIndex = bridgeModule.currentWorkoutInfo.exerciseIndex
|
||||
proxy.scrollTo(
|
||||
rowIdentifier(
|
||||
supersetIndex: currentSupersetIndex,
|
||||
@@ -152,7 +152,7 @@ struct ExerciseListView: View {
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
.sheet(item: $videoExercise) { exercise in
|
||||
PlayerView(player: $avPlayer)
|
||||
.onAppear{
|
||||
@@ -190,20 +190,34 @@ struct ExerciseListView: View {
|
||||
avPlayer.isMuted = true
|
||||
avPlayer.play()
|
||||
}
|
||||
|
||||
|
||||
func detailView(forExercise supersetExecercise: SupersetExercise) -> some View {
|
||||
VStack {
|
||||
VStack(spacing: WerkoutTheme.sm) {
|
||||
Text(supersetExecercise.exercise.description)
|
||||
.frame(alignment: .leading)
|
||||
Divider()
|
||||
.font(WerkoutTheme.bodyText)
|
||||
.foregroundStyle(WerkoutTheme.textSecondary)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
WerkoutTheme.divider.frame(height: 0.5)
|
||||
Text(supersetExecercise.exercise.muscles.map({ $0.name }).joined(separator: ", "))
|
||||
.frame(alignment: .leading)
|
||||
.font(WerkoutTheme.caption)
|
||||
.foregroundStyle(WerkoutTheme.accent)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct ExerciseListView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ExerciseListView(workout: PreviewData.workout(), showExecersizeInfo: .constant(true))
|
||||
ExerciseListView(
|
||||
workout: PreviewData.workout(),
|
||||
showExecersizeInfo: .constant(true),
|
||||
isInWorkout: false,
|
||||
currentSupersetIndex: 0,
|
||||
currentExerciseIndex: 0,
|
||||
allSupersetExecerciseIndex: 0,
|
||||
currentExercise: nil,
|
||||
currentWorkout: nil,
|
||||
goToExerciseAt: { _, _ in }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,11 +9,11 @@ import SwiftUI
|
||||
import AVKit
|
||||
|
||||
struct WorkoutDetailView: View {
|
||||
@StateObject var viewModel: WorkoutDetailViewModel
|
||||
@State var avPlayer = AVPlayer(url: URL(string: "https://dev.werkout.fitness/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4") ?? URL(fileURLWithPath: "/dev/null"))
|
||||
@ObservedObject var viewModel: WorkoutDetailViewModel
|
||||
@State private var avPlayer = AVPlayer(url: URL(string: BaseURLs.currentBaseURL + "/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4") ?? URL(fileURLWithPath: "/dev/null"))
|
||||
@State private var currentVideoURL: URL?
|
||||
|
||||
@StateObject var bridgeModule = BridgeModule.shared
|
||||
|
||||
@ObservedObject var bridgeModule = BridgeModule.shared
|
||||
@Environment(\.dismiss) var dismiss
|
||||
@AppStorage(Constants.phoneThotStyle) private var phoneThotStyle: ThotStyle = .never
|
||||
@AppStorage(Constants.thotGenderOption) private var thotGenderOption: String = "female"
|
||||
@@ -22,45 +22,50 @@ struct WorkoutDetailView: View {
|
||||
case completedWorkout([String: Any])
|
||||
var id: String { return "completedWorkoutSheet" }
|
||||
}
|
||||
|
||||
@State var workoutComplete: Sheet?
|
||||
@State var workoutToPlan: Workout?
|
||||
@State var showExecersizeInfo: Bool = false
|
||||
|
||||
|
||||
@State private var workoutComplete: Sheet?
|
||||
@State private var workoutToPlan: Workout?
|
||||
@State private var showExecersizeInfo: Bool = false
|
||||
|
||||
var body: some View {
|
||||
ZStack {
|
||||
WerkoutTheme.background.ignoresSafeArea()
|
||||
|
||||
switch viewModel.status {
|
||||
case .loading:
|
||||
Text("Loading")
|
||||
ProgressView()
|
||||
.tint(WerkoutTheme.accent)
|
||||
case .failed(let errorMessage):
|
||||
VStack(spacing: 16) {
|
||||
VStack(spacing: WerkoutTheme.md) {
|
||||
Text("Unable to load workout")
|
||||
.font(.headline)
|
||||
.font(WerkoutTheme.sectionTitle)
|
||||
.foregroundStyle(WerkoutTheme.textPrimary)
|
||||
Text(errorMessage)
|
||||
.font(.footnote)
|
||||
.font(WerkoutTheme.bodyText)
|
||||
.multilineTextAlignment(.center)
|
||||
.foregroundStyle(.secondary)
|
||||
.foregroundStyle(WerkoutTheme.textSecondary)
|
||||
}
|
||||
.padding()
|
||||
case .showWorkout(let workout):
|
||||
VStack(spacing: 0) {
|
||||
if bridgeModule.isInWorkout {
|
||||
HStack {
|
||||
CountdownView()
|
||||
CountdownView(
|
||||
currentExerciseDuration: bridgeModule.currentWorkoutInfo.currentExercise?.duration,
|
||||
currentExerciseTimeLeft: bridgeModule.currentExerciseTimeLeft
|
||||
)
|
||||
}
|
||||
.padding()
|
||||
.frame(maxWidth: .infinity)
|
||||
|
||||
|
||||
if phoneThotStyle != .off {
|
||||
GeometryReader { metrics in
|
||||
ZStack {
|
||||
PlayerView(player: $avPlayer)
|
||||
.frame(width: metrics.size.width * 1, height: metrics.size.height * 1)
|
||||
.onAppear{
|
||||
avPlayer.isMuted = true
|
||||
avPlayer.play()
|
||||
}
|
||||
|
||||
PlayerView(player: $avPlayer)
|
||||
.frame(height: 220)
|
||||
.onAppear{
|
||||
avPlayer.isMuted = true
|
||||
avPlayer.play()
|
||||
}
|
||||
.overlay(alignment: .bottomTrailing) {
|
||||
Button(action: {
|
||||
if let assetURL = ((avPlayer.currentItem?.asset) as? AVURLAsset)?.url,
|
||||
let currentExtercise = bridgeModule.currentWorkoutInfo.currentExercise,
|
||||
@@ -72,73 +77,86 @@ struct WorkoutDetailView: View {
|
||||
workout: bridgeModule.currentWorkoutInfo.workout) {
|
||||
updatePlayer(for: otherVideoURL)
|
||||
}
|
||||
}, label: {
|
||||
}) {
|
||||
Image(systemName: "arrow.triangle.2.circlepath.camera.fill")
|
||||
.frame(width: 44, height: 44)
|
||||
.foregroundColor(Color("appColor"))
|
||||
})
|
||||
.foregroundColor(.blue)
|
||||
.cornerRadius(Constants.buttonRadius)
|
||||
.frame(width: 160, height: 120)
|
||||
.position(x: metrics.size.width - 22, y: metrics.size.height - 30)
|
||||
.font(.title2)
|
||||
.padding(WerkoutTheme.sm)
|
||||
}
|
||||
.glassEffect(.regular.interactive())
|
||||
.tint(WerkoutTheme.accent)
|
||||
.padding(WerkoutTheme.sm)
|
||||
.accessibilityLabel("Switch video style")
|
||||
.accessibilityHint("Toggles between alternate and default exercise videos")
|
||||
|
||||
}
|
||||
.overlay(alignment: .bottomLeading) {
|
||||
Button(action: {
|
||||
showExecersizeInfo.toggle()
|
||||
}, label: {
|
||||
}) {
|
||||
Image(systemName: "info.circle.fill")
|
||||
.frame(width: 44, height: 44)
|
||||
.foregroundColor(Color("appColor"))
|
||||
})
|
||||
.foregroundColor(.blue)
|
||||
.cornerRadius(Constants.buttonRadius)
|
||||
.frame(width: 120, height: 120)
|
||||
.position(x: 22, y: metrics.size.height - 30)
|
||||
.font(.title2)
|
||||
.padding(WerkoutTheme.sm)
|
||||
}
|
||||
.glassEffect(.regular.interactive())
|
||||
.tint(WerkoutTheme.accent)
|
||||
.padding(WerkoutTheme.sm)
|
||||
.accessibilityLabel(showExecersizeInfo ? "Hide exercise info" : "Show exercise info")
|
||||
.accessibilityHint("Shows exercise description and target muscles")
|
||||
}
|
||||
}
|
||||
.padding([.top, .bottom])
|
||||
.background(Color(uiColor: .tertiarySystemBackground))
|
||||
.padding([.top, .bottom])
|
||||
.background(WerkoutTheme.background)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if !bridgeModule.isInWorkout {
|
||||
InfoView(workout: workout)
|
||||
.padding(.bottom)
|
||||
}
|
||||
|
||||
|
||||
if bridgeModule.isInWorkout {
|
||||
Divider()
|
||||
.background(Color(uiColor: .secondaryLabel))
|
||||
WerkoutTheme.divider.frame(height: 0.5)
|
||||
HStack {
|
||||
Text("\(bridgeModule.currentWorkoutInfo.currentRound) of \(bridgeModule.currentWorkoutInfo.numberOfRoundsInCurrentSuperSet)")
|
||||
.font(.title3)
|
||||
.bold()
|
||||
.font(.system(size: 17, weight: .bold, design: .monospaced))
|
||||
.foregroundStyle(WerkoutTheme.accent)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding(.leading, 10)
|
||||
|
||||
CurrentWorkoutElapsedTimeView()
|
||||
|
||||
CurrentWorkoutElapsedTimeView(
|
||||
currentWorkoutRunTimeInSeconds: bridgeModule.currentWorkoutRunTimeInSeconds
|
||||
)
|
||||
.frame(maxWidth: .infinity, alignment: .center)
|
||||
|
||||
|
||||
Text(progressText)
|
||||
.font(.title3)
|
||||
.bold()
|
||||
.font(.system(size: 17, weight: .bold, design: .monospaced))
|
||||
.foregroundStyle(WerkoutTheme.textPrimary)
|
||||
.frame(maxWidth: .infinity, alignment: .trailing)
|
||||
.padding(.trailing, 10)
|
||||
}
|
||||
.padding([.top, .bottom])
|
||||
.background(Color(uiColor: .tertiarySystemBackground))
|
||||
.background(WerkoutTheme.surfaceCard)
|
||||
}
|
||||
|
||||
Divider()
|
||||
.background(Color(uiColor: .secondaryLabel))
|
||||
|
||||
ExerciseListView(workout: workout, showExecersizeInfo: $showExecersizeInfo)
|
||||
|
||||
WerkoutTheme.divider.frame(height: 0.5)
|
||||
|
||||
ExerciseListView(
|
||||
workout: workout,
|
||||
showExecersizeInfo: $showExecersizeInfo,
|
||||
isInWorkout: bridgeModule.isInWorkout,
|
||||
currentSupersetIndex: bridgeModule.currentWorkoutInfo.supersetIndex,
|
||||
currentExerciseIndex: bridgeModule.currentWorkoutInfo.exerciseIndex,
|
||||
allSupersetExecerciseIndex: bridgeModule.currentWorkoutInfo.allSupersetExecerciseIndex,
|
||||
currentExercise: bridgeModule.currentWorkoutInfo.currentExercise,
|
||||
currentWorkout: bridgeModule.currentWorkoutInfo.workout,
|
||||
goToExerciseAt: { supersetIndex, exerciseIndex in
|
||||
bridgeModule.currentWorkoutInfo.goToExerciseAt(
|
||||
supersetIndex: supersetIndex,
|
||||
exerciseIndex: exerciseIndex
|
||||
)
|
||||
}
|
||||
)
|
||||
.padding([.top, .bottom], 10)
|
||||
.background(Color(uiColor: .systemGroupedBackground))
|
||||
|
||||
.background(WerkoutTheme.background)
|
||||
|
||||
ActionsView(completedWorkout: {
|
||||
bridgeModule.completeWorkout()
|
||||
}, planWorkout: { workout in
|
||||
@@ -146,8 +164,8 @@ struct WorkoutDetailView: View {
|
||||
}, workout: workout, showAddToCalendar: viewModel.isPreview, startWorkoutAction: {
|
||||
startWorkout(workout: workout)
|
||||
})
|
||||
.frame(height: 44)
|
||||
|
||||
.frame(height: 56)
|
||||
|
||||
}
|
||||
.sheet(item: $workoutComplete) { item in
|
||||
switch item {
|
||||
@@ -169,15 +187,16 @@ struct WorkoutDetailView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
.onChange(of: bridgeModule.currentWorkoutInfo.allSupersetExecerciseIndex, perform: { _ in
|
||||
.onChange(of: bridgeModule.currentWorkoutInfo.allSupersetExecerciseIndex) { _, _ in
|
||||
playVideos()
|
||||
})
|
||||
.onChange(of: bridgeModule.isInWorkout, perform: { _ in
|
||||
}
|
||||
.onChange(of: bridgeModule.isInWorkout) { _, _ in
|
||||
playVideos()
|
||||
})
|
||||
}
|
||||
.onAppear{
|
||||
viewModel.load()
|
||||
playVideos()
|
||||
|
||||
|
||||
bridgeModule.completedWorkout = {
|
||||
if let workoutData = createWorkoutData() {
|
||||
workoutComplete = .completedWorkout(workoutData)
|
||||
@@ -194,7 +213,7 @@ struct WorkoutDetailView: View {
|
||||
bridgeModule.completedWorkout = nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
func playVideos() {
|
||||
if let currentExtercise = bridgeModule.currentWorkoutInfo.currentExercise {
|
||||
if let videoURL = VideoURLCreator.videoURL(
|
||||
@@ -221,7 +240,7 @@ struct WorkoutDetailView: View {
|
||||
avPlayer.isMuted = true
|
||||
avPlayer.play()
|
||||
}
|
||||
|
||||
|
||||
func startWorkout(workout: Workout) {
|
||||
bridgeModule.start(workout: workout)
|
||||
}
|
||||
@@ -235,7 +254,7 @@ struct WorkoutDetailView: View {
|
||||
let current = min(totalExercises, max(1, bridgeModule.currentWorkoutInfo.allSupersetExecerciseIndex + 1))
|
||||
return "\(current)/\(totalExercises)"
|
||||
}
|
||||
|
||||
|
||||
func createWorkoutData() -> [String:Any]? {
|
||||
guard let workoutid = bridgeModule.currentWorkoutInfo.workout?.id,
|
||||
let startTime = bridgeModule.workoutStartDate?.timeFormatForUpload,
|
||||
@@ -249,7 +268,7 @@ struct WorkoutDetailView: View {
|
||||
"workout": workoutid,
|
||||
"total_time": bridgeModule.currentWorkoutRunTimeInSeconds
|
||||
] as [String : Any]
|
||||
|
||||
|
||||
return postBody
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,26 +17,32 @@ class WorkoutDetailViewModel: ObservableObject {
|
||||
|
||||
@Published var status: WorkoutDetailViewModelStatus
|
||||
let isPreview: Bool
|
||||
|
||||
let workout: Workout
|
||||
|
||||
init(workout: Workout, status: WorkoutDetailViewModelStatus? = nil, isPreview: Bool) {
|
||||
self.status = .loading
|
||||
self.workout = workout
|
||||
self.isPreview = isPreview
|
||||
|
||||
|
||||
if let passedStatus = status {
|
||||
self.status = passedStatus
|
||||
} else {
|
||||
WorkoutDetailFetchable(workoutID: workout.id).fetch(completion: { result in
|
||||
switch result {
|
||||
case .success(let model):
|
||||
DispatchQueue.main.async {
|
||||
self.status = .showWorkout(model)
|
||||
}
|
||||
case .failure(let failure):
|
||||
DispatchQueue.main.async {
|
||||
self.status = .failed("Failed to load workout details: \(failure.localizedDescription)")
|
||||
}
|
||||
}
|
||||
})
|
||||
self.status = .loading
|
||||
}
|
||||
}
|
||||
|
||||
func load() {
|
||||
guard case .loading = status else { return }
|
||||
WorkoutDetailFetchable(workoutID: workout.id).fetch(completion: { result in
|
||||
switch result {
|
||||
case .success(let model):
|
||||
DispatchQueue.main.async {
|
||||
self.status = .showWorkout(model)
|
||||
}
|
||||
case .failure(let failure):
|
||||
DispatchQueue.main.async {
|
||||
self.status = .failed("Failed to load workout details: \(failure.localizedDescription)")
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user