fix: codebase audit fixes — safety, accessibility, and production hygiene

Address 16 issues from external audit:
- Move StoreKit transaction listener ownership to StoreManager singleton with proper deinit
- Remove noisy VoiceOver announcements, add missing accessibility on StatPill and BootstrapLoadingView
- Replace String @retroactive Identifiable with IdentifiableShareCode wrapper
- Add crash guard in AchievementEngine getContributingVisitIds + cache stadium lookups
- Pre-compute GamesHistoryViewModel filtered properties to avoid redundant SwiftUI recomputation
- Remove force-unwraps in ProgressMapView with safe guard-let fallback
- Add diff-based update gating in ItineraryTableViewWrapper to prevent unnecessary reloads
- Replace deprecated UIScreen.main with UIWindowScene lookup
- Add deinit task cancellation in ScheduleViewModel and SuggestedTripsGenerator
- Wrap ~234 unguarded print() calls across 27 files in #if DEBUG

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Trey t
2026-02-22 00:07:53 -06:00
parent 826eadbc0f
commit 91c5eac22d
32 changed files with 434 additions and 67 deletions

View File

@@ -7,40 +7,17 @@ final class GamesHistoryViewModel {
private let modelContext: ModelContext
var allVisits: [StadiumVisit] = []
var selectedSports: Set<Sport> = []
var selectedSports: Set<Sport> = [] {
didSet { recomputeFilteredData() }
}
var isLoading = false
var error: String?
// Computed: visits grouped by year
var visitsByYear: [Int: [StadiumVisit]] {
let calendar = Calendar.current
let filtered = filteredVisits
return Dictionary(grouping: filtered) { visit in
calendar.component(.year, from: visit.visitDate)
}
}
// Computed: sorted year keys (descending)
var sortedYears: [Int] {
visitsByYear.keys.sorted(by: >)
}
// Computed: filtered by selected sports
var filteredVisits: [StadiumVisit] {
guard !selectedSports.isEmpty else { return allVisits }
return allVisits.filter { visit in
guard let stadium = AppDataProvider.shared.stadium(for: visit.stadiumId) else {
return false
}
return selectedSports.contains(stadium.sport)
}
}
// Total count
var totalGamesCount: Int {
filteredVisits.count
}
// Pre-computed stored properties (updated via recomputeFilteredData)
private(set) var filteredVisits: [StadiumVisit] = []
private(set) var visitsByYear: [Int: [StadiumVisit]] = [:]
private(set) var sortedYears: [Int] = []
private(set) var totalGamesCount: Int = 0
init(modelContext: ModelContext) {
self.modelContext = modelContext
@@ -60,6 +37,8 @@ final class GamesHistoryViewModel {
self.error = "Failed to load games: \(error.localizedDescription)"
allVisits = []
}
recomputeFilteredData()
}
func toggleSport(_ sport: Sport) {
@@ -73,4 +52,24 @@ final class GamesHistoryViewModel {
func clearFilters() {
selectedSports.removeAll()
}
private func recomputeFilteredData() {
if selectedSports.isEmpty {
filteredVisits = allVisits
} else {
filteredVisits = allVisits.filter { visit in
guard let stadium = AppDataProvider.shared.stadium(for: visit.stadiumId) else {
return false
}
return selectedSports.contains(stadium.sport)
}
}
let calendar = Calendar.current
visitsByYear = Dictionary(grouping: filteredVisits) { visit in
calendar.component(.year, from: visit.visitDate)
}
sortedYears = visitsByYear.keys.sorted(by: >)
totalGamesCount = filteredVisits.count
}
}