Fix 28 issues from deep audit and UI audit + redesign changes
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:
Trey t
2026-02-23 10:24:06 -06:00
parent 921829f2c3
commit 5d39dcb66f
60 changed files with 1783 additions and 1346 deletions

View File

@@ -12,8 +12,8 @@ struct CreateExerciseActionsView: View {
@ObservedObject var workoutExercise: CreateWorkoutExercise
@ObservedObject var superset: CreateWorkoutSuperSet
var viewModel: WorkoutViewModel
@State var avPlayer = AVPlayer(url: URL(string: "https://dev.werkout.fitness/media/exercise_videos/2_Dumbbell_Lateral_Lunges.mp4") ?? URL(fileURLWithPath: "/dev/null"))
@State 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?
@State var videoExercise: Exercise? {
didSet {
@@ -23,90 +23,103 @@ struct CreateExerciseActionsView: View {
}
}
}
var body: some View {
VStack {
VStack {
VStack(spacing: WerkoutTheme.sm) {
VStack(spacing: WerkoutTheme.xs) {
HStack {
Text("Reps: ")
.font(WerkoutTheme.bodyText)
.foregroundStyle(WerkoutTheme.textSecondary)
Text("\(workoutExercise.reps)")
.foregroundColor(workoutExercise.reps == 0 && workoutExercise.duration == 0 ? .red : Color(uiColor: .label))
.foregroundColor(workoutExercise.reps == 0 && workoutExercise.duration == 0 ? WerkoutTheme.danger : WerkoutTheme.textPrimary)
.font(WerkoutTheme.bodyText)
.bold()
Stepper("", onIncrement: {
workoutExercise.increaseReps()
}, onDecrement: {
workoutExercise.decreaseReps()
})
.tint(WerkoutTheme.accent)
.accessibilityLabel("Reps")
}
}
HStack {
Text("Weight: ")
.font(WerkoutTheme.bodyText)
.foregroundStyle(WerkoutTheme.textSecondary)
Text("\(workoutExercise.weight)")
.font(WerkoutTheme.bodyText)
.foregroundStyle(WerkoutTheme.textPrimary)
Stepper("", onIncrement: {
workoutExercise.increaseWeight()
}, onDecrement: {
workoutExercise.decreaseWeight()
})
.tint(WerkoutTheme.accent)
.accessibilityLabel("Weight")
}
HStack {
Text("Duration: ")
.font(WerkoutTheme.bodyText)
.foregroundStyle(WerkoutTheme.textSecondary)
Text("\(workoutExercise.duration)")
.foregroundColor(
workoutExercise.reps == 0 && workoutExercise.duration == 0 ? .red : Color(
uiColor: .label
)
workoutExercise.reps == 0 && workoutExercise.duration == 0 ? WerkoutTheme.danger : WerkoutTheme.textPrimary
)
.font(WerkoutTheme.bodyText)
.bold()
Stepper("", onIncrement: {
workoutExercise.increaseDuration()
}, onDecrement: {
workoutExercise.decreaseDuration()
})
.tint(WerkoutTheme.accent)
.accessibilityLabel("Duration")
}
HStack {
Spacer()
Button(action: {
videoExercise = workoutExercise.exercise
}) {
Image(systemName: "video.fill")
GlassEffectContainer {
HStack {
Spacer()
Button(action: {
videoExercise = workoutExercise.exercise
}) {
Image(systemName: "video.fill")
.foregroundStyle(WerkoutTheme.textPrimary)
}
.frame(width: 88, height: 44)
.glassEffect(.regular.interactive())
.tint(WerkoutTheme.accent)
.buttonStyle(BorderlessButtonStyle())
.accessibilityLabel("Preview exercise video")
.accessibilityHint("Opens a video preview for this exercise")
Spacer()
Spacer()
Button(action: {
superset
.deleteExerciseForChosenSuperset(exercise: workoutExercise)
viewModel.increaseRandomNumberForUpdating()
}) {
Image(systemName: "trash.fill")
.foregroundStyle(WerkoutTheme.textPrimary)
}
.frame(width: 88, height: 44)
.glassEffect(.regular.interactive())
.tint(WerkoutTheme.danger)
.buttonStyle(BorderlessButtonStyle())
.accessibilityLabel("Delete exercise")
.accessibilityHint("Removes this exercise from the superset")
Spacer()
}
.frame(width: 88, height: 44)
.foregroundColor(.white)
.background(.blue)
.cornerRadius(Constants.buttonRadius)
.buttonStyle(BorderlessButtonStyle())
.accessibilityLabel("Preview exercise video")
.accessibilityHint("Opens a video preview for this exercise")
Spacer()
Spacer()
Button(action: {
superset
.deleteExerciseForChosenSuperset(exercise: workoutExercise)
viewModel.increaseRandomNumberForUpdating()
}) {
Image(systemName: "trash.fill")
}
.frame(width: 88, height: 44)
.foregroundColor(.white)
.background(.red)
.cornerRadius(Constants.buttonRadius)
.buttonStyle(BorderlessButtonStyle())
.accessibilityLabel("Delete exercise")
.accessibilityHint("Removes this exercise from the superset")
Spacer()
}
}
.sheet(item: $videoExercise) { exercise in

View File

@@ -5,7 +5,8 @@
// Created by Trey Tartt on 6/18/23.
//
import SwiftUI
import Combine
import Foundation
import SharedCore
class CreateWorkoutExercise: ObservableObject, Identifiable {
@@ -93,6 +94,9 @@ class WorkoutViewModel: ObservableObject {
@Published var description = String()
@Published var validationError: String?
@Published var isUploading = false
// MARK: - Manual Invalidation
// Workaround: nested ObservableObject changes don't propagate to parent.
// Remove when migrating to @Observable (iOS 17+).
@Published var randomValueForUpdatingValue = 0
func increaseRandomNumberForUpdating() {
@@ -112,7 +116,32 @@ class WorkoutViewModel: ObservableObject {
increaseRandomNumberForUpdating()
}
}
func addExercise(_ exercise: Exercise, to superset: CreateWorkoutSuperSet) {
let workoutExercise = CreateWorkoutExercise(exercise: exercise)
superset.exercises.append(workoutExercise)
if exercise.side?.isEmpty == false {
autoAddSiblingExercises(for: exercise, to: superset)
}
increaseRandomNumberForUpdating()
}
private func autoAddSiblingExercises(for exercise: Exercise, to superset: CreateWorkoutSuperSet) {
guard let allExercises = DataStore.shared.allExercise else { return }
let siblings = allExercises.filter { $0.name == exercise.name }
guard siblings.count == 2,
let recover = allExercises.first(where: { $0.name.lowercased() == "recover" }) else { return }
let recoverExercise = CreateWorkoutExercise(exercise: recover)
superset.exercises.append(recoverExercise)
for sibling in siblings where sibling.id != exercise.id {
let otherSideExercise = CreateWorkoutExercise(exercise: sibling)
superset.exercises.append(otherSideExercise)
}
}
func showRoundsError() {
validationError = "Each superset must have at least one round."
}

View File

@@ -15,16 +15,16 @@ struct CreateWorkoutItemPickerModel {
class CreateWorkoutItemPickerViewModel: Identifiable, ObservableObject {
let allValues: [CreateWorkoutItemPickerModel]
@Published var selectedIds: [Int]
@Published var selectedIds: Set<Int>
init(allValues: [CreateWorkoutItemPickerModel], selectedIds: [Int]) {
self.allValues = allValues
self.selectedIds = selectedIds
self.selectedIds = Set(selectedIds)
}
func toggleAll() {
if selectedIds.isEmpty {
selectedIds.append(contentsOf: allValues.map({ $0.id }))
selectedIds = Set(allValues.map({ $0.id }))
} else {
selectedIds.removeAll()
}
@@ -38,65 +38,71 @@ struct CreateWorkoutItemPickerView: View {
@State var searchString: String = ""
var body: some View {
VStack {
VStack(spacing: 0) {
List() {
ForEach(viewModel.allValues, id:\.self.id) { value in
if searchString.isEmpty || value.name.lowercased().contains(searchString.lowercased()) {
HStack {
HStack(spacing: WerkoutTheme.sm) {
Circle()
.stroke(.blue, lineWidth: 1)
.background(Circle().fill(viewModel.selectedIds.contains(value.id) ? .blue :.clear))
.stroke(WerkoutTheme.accent, lineWidth: 1.5)
.background(Circle().fill(viewModel.selectedIds.contains(value.id) ? WerkoutTheme.accent : Color.clear))
.frame(width: 33, height: 33)
Text(value.name)
.font(WerkoutTheme.bodyText)
.foregroundStyle(WerkoutTheme.textPrimary)
}
.contentShape(Rectangle())
.onTapGesture {
if viewModel.selectedIds.contains(value.id) {
if let idx = viewModel.selectedIds.firstIndex(of: value.id){
viewModel.selectedIds.remove(at: idx)
}
viewModel.selectedIds.remove(value.id)
} else {
viewModel.selectedIds.append(value.id)
viewModel.selectedIds.insert(value.id)
}
}
.listRowBackground(WerkoutTheme.surfaceCard)
}
}
}
TextField("Filter", text: $searchString)
.padding()
HStack {
Button(action: {
viewModel.toggleAll()
}, label: {
Image(systemName: "checklist")
.font(.title)
})
.frame(maxWidth: 44, alignment: .center)
.frame(height: 44)
.foregroundColor(.green)
.background(.white)
.cornerRadius(Constants.buttonRadius)
.padding()
.scrollContentBackground(.hidden)
.background(WerkoutTheme.background)
Button(action: {
completed(viewModel.selectedIds)
dismiss()
}, label: {
Text("done")
})
.frame(maxWidth: .infinity, alignment: .center)
.frame(height: 44)
.foregroundColor(.blue)
.background(.yellow)
.cornerRadius(Constants.buttonRadius)
.padding()
.frame(maxWidth: .infinity)
TextField("Filter", text: $searchString)
.werkoutTextField()
.padding(.horizontal, WerkoutTheme.md)
.padding(.vertical, WerkoutTheme.sm)
GlassEffectContainer {
HStack(spacing: WerkoutTheme.md) {
Button(action: {
viewModel.toggleAll()
}, label: {
Image(systemName: "checklist")
.font(.title)
.foregroundStyle(WerkoutTheme.textPrimary)
})
.frame(width: 44, height: 44)
.glassEffect(.regular.interactive())
.tint(WerkoutTheme.success)
Button(action: {
completed(Array(viewModel.selectedIds))
dismiss()
}, label: {
Text("Done")
.font(.system(size: 16, weight: .bold))
.foregroundStyle(WerkoutTheme.textPrimary)
.frame(maxWidth: .infinity)
.frame(height: 44)
})
.glassEffect(.regular.interactive())
.tint(WerkoutTheme.accent)
}
.padding(.horizontal, WerkoutTheme.md)
.padding(.vertical, WerkoutTheme.sm)
}
}
.background(WerkoutTheme.background)
}
}
@@ -104,10 +110,10 @@ struct CreateWorkoutItemPickerView_Previews: PreviewProvider {
static let fakeValues = [CreateWorkoutItemPickerModel(id: 1, name: "one"),
CreateWorkoutItemPickerModel(id: 2, name: "two"),
CreateWorkoutItemPickerModel(id: 3, name: "three")]
static var previews: some View {
CreateWorkoutItemPickerView(viewModel: CreateWorkoutItemPickerViewModel(allValues: fakeValues, selectedIds: [1]), completed: { selectedIds in
})
}
}

View File

@@ -16,21 +16,21 @@ struct CreateWorkoutMainView: View {
viewModel.title.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty == false &&
viewModel.isUploading == false
}
var body: some View {
VStack {
VStack {
VStack(spacing: 0) {
VStack(spacing: WerkoutTheme.sm) {
TextField("Title", text: $viewModel.title)
.padding(.horizontal)
.textFieldStyle(.roundedBorder)
.werkoutTextField()
.padding(.horizontal, WerkoutTheme.md)
TextField("Description", text: $viewModel.description)
.padding(.horizontal)
.textFieldStyle(.roundedBorder)
.werkoutTextField()
.padding(.horizontal, WerkoutTheme.md)
}
.padding(.bottom)
.background(Color(uiColor: .systemGray5))
.padding(.vertical, WerkoutTheme.md)
.background(WerkoutTheme.surfaceCard)
ScrollViewReader { proxy in
List() {
ForEach(viewModel.superSets) { superset in
@@ -40,6 +40,7 @@ struct CreateWorkoutMainView: View {
superset: superset,
viewModel: viewModel)
}
.listRowBackground(WerkoutTheme.surfaceCard)
// 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
@@ -48,91 +49,70 @@ struct CreateWorkoutMainView: View {
.accessibilityHidden(true)
.id(999)
.listRowSeparator(.hidden)
.listRowBackground(Color.clear)
}
.onChange(of: viewModel.randomValueForUpdatingValue, perform: { newValue in
.scrollContentBackground(.hidden)
.background(WerkoutTheme.background)
.onChange(of: viewModel.randomValueForUpdatingValue) { _, _ in
withAnimation {
proxy.scrollTo(999, anchor: .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?.isEmpty == false {
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)
}
}
}
}
if let superset = selectedCreateWorkoutSuperSet {
viewModel.addExercise(exercise, to: superset)
}
viewModel.increaseRandomNumberForUpdating()
selectedCreateWorkoutSuperSet = nil
})
}
HStack {
Button("Add Superset", action: {
viewModel.addNewSuperset()
})
.frame(maxWidth: .infinity, alignment: .center)
.frame(height: 44)
.foregroundColor(.white)
.background(.blue)
.cornerRadius(Constants.buttonRadius)
.padding()
.frame(maxWidth: .infinity)
.accessibilityLabel("Add superset")
.accessibilityHint("Adds a new superset section to this workout")
Divider()
Button(action: {
viewModel.uploadWorkout()
}, label: {
if viewModel.isUploading {
ProgressView()
.progressViewStyle(.circular)
.tint(.white)
} else {
Text("Done")
}
})
.frame(maxWidth: .infinity, alignment: .center)
.frame(height: 44)
.foregroundColor(.white)
.background(.green)
.cornerRadius(Constants.buttonRadius)
.padding()
.frame(maxWidth: .infinity)
.disabled(canSubmit == false)
.accessibilityLabel("Upload workout")
.accessibilityHint("Uploads this workout to your account")
}
.frame(height: 44)
Divider()
.overlay(WerkoutTheme.divider)
GlassEffectContainer {
HStack(spacing: WerkoutTheme.md) {
Button(action: {
viewModel.addNewSuperset()
}) {
Label("Add Superset", systemImage: "plus.circle.fill")
.font(.system(size: 15, weight: .bold))
.foregroundStyle(WerkoutTheme.textPrimary)
.frame(maxWidth: .infinity)
.frame(height: 44)
}
.glassEffect(.regular.interactive())
.tint(WerkoutTheme.accent)
.accessibilityLabel("Add superset")
.accessibilityHint("Adds a new superset section to this workout")
Button(action: {
viewModel.uploadWorkout()
}, label: {
if viewModel.isUploading {
ProgressView()
.progressViewStyle(.circular)
.tint(WerkoutTheme.textPrimary)
} else {
Text("Done")
.font(.system(size: 15, weight: .bold))
.foregroundStyle(WerkoutTheme.textPrimary)
}
})
.frame(maxWidth: .infinity)
.frame(height: 44)
.glassEffect(.regular.interactive())
.tint(WerkoutTheme.success)
.disabled(canSubmit == false)
.accessibilityLabel("Upload workout")
.accessibilityHint("Uploads this workout to your account")
}
.padding(.horizontal, WerkoutTheme.md)
.padding(.vertical, WerkoutTheme.sm)
}
}
.background(Color(uiColor: .systemGray5))
.background(WerkoutTheme.background)
.alert("Create Workout", isPresented: Binding<Bool>(
get: { viewModel.validationError != nil },
set: { _ in viewModel.validationError = nil }

View File

@@ -12,32 +12,38 @@ struct CreateWorkoutSupersetActionsView: View {
@Binding var showAddExercise: Bool
var viewModel: WorkoutViewModel
@Binding var selectedCreateWorkoutSuperSet: CreateWorkoutSuperSet?
var body: some View {
HStack {
Button(action: {
selectedCreateWorkoutSuperSet = workoutSuperSet
showAddExercise.toggle()
}) {
Text("Add exercise")
.padding()
}
.foregroundColor(.white)
.background(.green)
.frame(maxWidth: .infinity, alignment: .center)
Button(action: {
GlassEffectContainer {
HStack(spacing: WerkoutTheme.md) {
Button(action: {
selectedCreateWorkoutSuperSet = workoutSuperSet
showAddExercise.toggle()
}) {
Text("Add exercise")
.font(.system(size: 15, weight: .bold))
.foregroundStyle(WerkoutTheme.textPrimary)
.padding()
}
.glassEffect(.regular.interactive())
.tint(WerkoutTheme.success)
.frame(maxWidth: .infinity, alignment: .center)
Button(action: {
// viewModel.delete(superset: workoutSuperSet)
// viewModel.increaseRandomNumberForUpdating()
// viewModel.objectWillChange.send()
}) {
Text("Delete superset")
.padding()
}) {
Text("Delete superset")
.font(.system(size: 15, weight: .bold))
.foregroundStyle(WerkoutTheme.textPrimary)
.padding()
}
.glassEffect(.regular.interactive())
.tint(WerkoutTheme.danger)
.frame(maxWidth: .infinity, alignment: .center)
}
.foregroundColor(.white)
.background(.red)
.frame(maxWidth: .infinity, alignment: .center)
}
}
}