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:
@@ -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
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user