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>
120 lines
4.3 KiB
Swift
120 lines
4.3 KiB
Swift
//
|
|
// CreateWorkoutItemPicker.swift
|
|
// Werkout_ios
|
|
//
|
|
// Created by Trey Tartt on 6/25/23.
|
|
//
|
|
|
|
import SwiftUI
|
|
import Combine
|
|
|
|
struct CreateWorkoutItemPickerModel {
|
|
let id: Int
|
|
let name: String
|
|
}
|
|
|
|
class CreateWorkoutItemPickerViewModel: Identifiable, ObservableObject {
|
|
let allValues: [CreateWorkoutItemPickerModel]
|
|
@Published var selectedIds: Set<Int>
|
|
|
|
init(allValues: [CreateWorkoutItemPickerModel], selectedIds: [Int]) {
|
|
self.allValues = allValues
|
|
self.selectedIds = Set(selectedIds)
|
|
}
|
|
|
|
func toggleAll() {
|
|
if selectedIds.isEmpty {
|
|
selectedIds = Set(allValues.map({ $0.id }))
|
|
} else {
|
|
selectedIds.removeAll()
|
|
}
|
|
}
|
|
}
|
|
|
|
struct CreateWorkoutItemPickerView: View {
|
|
@ObservedObject var viewModel: CreateWorkoutItemPickerViewModel
|
|
var completed: (([Int]) -> Void)
|
|
@Environment(\.dismiss) var dismiss
|
|
@State var searchString: String = ""
|
|
|
|
var body: some View {
|
|
VStack(spacing: 0) {
|
|
List() {
|
|
ForEach(viewModel.allValues, id:\.self.id) { value in
|
|
if searchString.isEmpty || value.name.lowercased().contains(searchString.lowercased()) {
|
|
HStack(spacing: WerkoutTheme.sm) {
|
|
Circle()
|
|
.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) {
|
|
viewModel.selectedIds.remove(value.id)
|
|
} else {
|
|
viewModel.selectedIds.insert(value.id)
|
|
}
|
|
}
|
|
.listRowBackground(WerkoutTheme.surfaceCard)
|
|
}
|
|
}
|
|
}
|
|
.scrollContentBackground(.hidden)
|
|
.background(WerkoutTheme.background)
|
|
|
|
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)
|
|
}
|
|
}
|
|
|
|
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
|
|
|
|
})
|
|
}
|
|
}
|