Fixes ~95 issues from deep audit across 12 categories in 82 files: - Crash prevention: double-resume in PhotoMetadataExtractor, force unwraps in DateRangePicker, array bounds checks in polls/achievements, ProGate hit-test bypass, Dictionary(uniqueKeysWithValues:) → uniquingKeysWith in 4 files - Silent failure elimination: all 34 try? sites replaced with do/try/catch + logging (SavedTrip, TripDetailView, CanonicalSyncService, BootstrapService, CanonicalModels, CKModels, SportsTimeApp, and more) - Performance: cached DateFormatters (7 files), O(1) team lookups via AppDataProvider, achievement definition dictionary, AnimatedBackground consolidated from 19 Tasks to 1, task cancellation in SharePreviewView - Concurrency: UIKit drawing → MainActor.run, background fetch timeout guard, @MainActor on ThemeManager/AppearanceManager, SyncLogger read/write race fix - Planning engine: game end time in travel feasibility, state-aware city normalization, exact city matching, DrivingConstraints parameter propagation - IAP: unknown subscription states → expired, unverified transaction logging, entitlements updated before paywall dismiss, restore visible to all users - Security: API key to Info.plist lookup, filename sanitization in PDF export, honest User-Agent, removed stale "Feels" analytics super properties - Navigation: consolidated competing navigationDestination, boolean → value-based - Testing: 8 sleep() → waitForExistence, duplicates extracted, Swift 6 compat - Service bugs: infinite retry cap, duplicate achievement prevention, TOCTOU vote fix, PollVote.odg → voterId rename, deterministic placeholder IDs, parallel MKDirections, Sendable-safe POI struct Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
145 lines
4.7 KiB
Swift
145 lines
4.7 KiB
Swift
//
|
|
// PollCreationView.swift
|
|
// SportsTime
|
|
//
|
|
// View for creating a new trip poll
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct PollCreationView: View {
|
|
@Environment(\.dismiss) private var dismiss
|
|
@Environment(\.colorScheme) private var colorScheme
|
|
@State private var viewModel = PollCreationViewModel()
|
|
@State private var showError = false
|
|
|
|
let trips: [Trip]
|
|
var onPollCreated: ((TripPoll) -> Void)?
|
|
|
|
var body: some View {
|
|
NavigationStack {
|
|
Form {
|
|
Section {
|
|
TextField("Poll Title", text: $viewModel.title)
|
|
.textInputAutocapitalization(.words)
|
|
.accessibilityHint("Enter a descriptive name for your poll")
|
|
} header: {
|
|
Text("Title")
|
|
} footer: {
|
|
Text("Give your poll a name, like \"Summer Road Trip Options\"")
|
|
}
|
|
|
|
Section {
|
|
ForEach(trips) { trip in
|
|
TripSelectionRow(
|
|
trip: trip,
|
|
isSelected: viewModel.selectedTripIds.contains(trip.id)
|
|
) {
|
|
viewModel.toggleTrip(trip.id)
|
|
}
|
|
}
|
|
} header: {
|
|
Text("Select Trips (\(viewModel.selectedTripIds.count) selected)")
|
|
} footer: {
|
|
if let message = viewModel.validationMessage {
|
|
Text(message)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
}
|
|
.scrollContentBackground(.hidden)
|
|
.themedBackground()
|
|
.navigationTitle("Create Poll")
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.toolbar {
|
|
ToolbarItem(placement: .cancellationAction) {
|
|
Button("Cancel") {
|
|
dismiss()
|
|
}
|
|
}
|
|
|
|
ToolbarItem(placement: .confirmationAction) {
|
|
Button("Create") {
|
|
Task {
|
|
await viewModel.createPoll(trips: trips)
|
|
}
|
|
}
|
|
.disabled(!viewModel.canCreate || viewModel.isLoading)
|
|
}
|
|
}
|
|
.overlay {
|
|
if viewModel.isLoading {
|
|
ProgressView()
|
|
.scaleEffect(1.2)
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
.background(.ultraThinMaterial)
|
|
}
|
|
}
|
|
.alert("Error", isPresented: $showError) {
|
|
Button("OK") {
|
|
viewModel.error = nil
|
|
}
|
|
} message: {
|
|
if let error = viewModel.error {
|
|
Text(error.localizedDescription)
|
|
}
|
|
}
|
|
.onChange(of: viewModel.error != nil) { _, hasError in
|
|
showError = hasError
|
|
}
|
|
.onChange(of: viewModel.createdPoll) { _, newPoll in
|
|
if let poll = newPoll {
|
|
onPollCreated?(poll)
|
|
dismiss()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - Trip Selection Row
|
|
|
|
private struct TripSelectionRow: View {
|
|
@Environment(\.colorScheme) private var colorScheme
|
|
let trip: Trip
|
|
let isSelected: Bool
|
|
let onTap: () -> Void
|
|
|
|
var body: some View {
|
|
Button(action: onTap) {
|
|
HStack {
|
|
VStack(alignment: .leading, spacing: 4) {
|
|
Text(trip.displayName)
|
|
.font(.headline)
|
|
.foregroundStyle(Theme.textPrimary(colorScheme))
|
|
|
|
Text(tripSummary)
|
|
.font(.subheadline)
|
|
.foregroundStyle(Theme.textSecondary(colorScheme))
|
|
}
|
|
|
|
Spacer()
|
|
|
|
Image(systemName: isSelected ? "checkmark.circle.fill" : "circle")
|
|
.font(.title2)
|
|
.foregroundStyle(isSelected ? Theme.warmOrange : Theme.textMuted(colorScheme))
|
|
.accessibilityHidden(true)
|
|
}
|
|
.contentShape(Rectangle())
|
|
}
|
|
.buttonStyle(.plain)
|
|
.accessibilityValue(isSelected ? "Selected" : "Not selected")
|
|
.accessibilityAddTraits(isSelected ? .isSelected : [])
|
|
}
|
|
|
|
private var tripSummary: String {
|
|
let stopCount = trip.stops.count
|
|
let gameCount = trip.stops.flatMap { $0.games }.count
|
|
return "\(stopCount) stops, \(gameCount) games"
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
PollCreationView(trips: [])
|
|
}
|