From e70b9faab83af7a3faf1c07a0e620970e47c0f21 Mon Sep 17 00:00:00 2001 From: Trey t Date: Mon, 12 Jan 2026 11:09:50 -0600 Subject: [PATCH] fix: show all team games (home and away) when browsing by team Previously, browsing by team (e.g., Houston Astros) only showed home games. Now games are associated with both home AND away teams, so selecting a team shows all their games regardless of whether they're playing at home or away. Co-Authored-By: Claude Opus 4.5 --- .../Trip/Views/TripCreationView.swift | 26 ++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/SportsTime/Features/Trip/Views/TripCreationView.swift b/SportsTime/Features/Trip/Views/TripCreationView.swift index 2597a19..e1260f4 100644 --- a/SportsTime/Features/Trip/Views/TripCreationView.swift +++ b/SportsTime/Features/Trip/Views/TripCreationView.swift @@ -956,24 +956,38 @@ struct GamePickerSheet: View { @State private var expandedSports: Set = [] @State private var expandedTeams: Set = [] - // Group games by Sport → Team (home team only to avoid duplicates) + // Group games by Sport → Team (both home and away teams so browsing shows all team games) private var gamesBySport: [Sport: [TeamWithGames]] { var result: [Sport: [String: TeamWithGames]] = [:] for game in games { let sport = game.game.sport - let team = game.homeTeam if result[sport] == nil { result[sport] = [:] } - if var teamData = result[sport]?[team.id] { + // Add game to home team's list + let homeTeam = game.homeTeam + if var teamData = result[sport]?[homeTeam.id] { teamData.games.append(game) - result[sport]?[team.id] = teamData + result[sport]?[homeTeam.id] = teamData } else { - result[sport]?[team.id] = TeamWithGames( - team: team, + result[sport]?[homeTeam.id] = TeamWithGames( + team: homeTeam, + sport: sport, + games: [game] + ) + } + + // Also add game to away team's list (so browsing by team shows all games) + let awayTeam = game.awayTeam + if var teamData = result[sport]?[awayTeam.id] { + teamData.games.append(game) + result[sport]?[awayTeam.id] = teamData + } else { + result[sport]?[awayTeam.id] = TeamWithGames( + team: awayTeam, sport: sport, games: [game] )