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] )