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 <noreply@anthropic.com>
This commit is contained in:
@@ -956,24 +956,38 @@ struct GamePickerSheet: View {
|
||||
@State private var expandedSports: Set<Sport> = []
|
||||
@State private var expandedTeams: Set<String> = []
|
||||
|
||||
// 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]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user