From c76a9e2152fd752b3abfad7e829eae03b1fb8e75 Mon Sep 17 00:00:00 2001 From: Duru Alayli Date: Wed, 25 Mar 2026 17:43:42 -0400 Subject: [PATCH 1/2] sort sports by upcoming --- score-ios/ViewModels/GamesViewModel.swift | 25 +++++++++++++++++++ .../Views/ListViews/SportSelectorView.swift | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/score-ios/ViewModels/GamesViewModel.swift b/score-ios/ViewModels/GamesViewModel.swift index e9cc9aa..38e84ab 100644 --- a/score-ios/ViewModels/GamesViewModel.swift +++ b/score-ios/ViewModels/GamesViewModel.swift @@ -300,6 +300,31 @@ class GamesViewModel: ObservableObject func retryFetch() { fetchGames() } + + func orderSportsByUpcoming(sports: [Sport]) -> [Sport] { + let allOtherSports = Sport.allCases.filter { $0 != .All } + let (withGames, withoutGames) = allOtherSports.reduce(into: ([Sport](), [Sport]())) { acc, sport in + if allUpcomingGames.contains(where: { $0.sport == sport }) { + acc.0.append(sport) + } else { + acc.1.append(sport) + } + } + let nextGameBySport: [Sport: Date] = Dictionary(uniqueKeysWithValues: + withGames.map { sport in + let nextDate = allUpcomingGames + .filter { $0.sport == sport } + .map { $0.date } + .min() ?? Date.distantFuture + return (sport, nextDate) + } + ) + let sortedWithGames = withGames.sorted { s1, s2 in + (nextGameBySport[s1] ?? Date.distantFuture) < (nextGameBySport[s2] ?? Date.distantFuture) + } + let sortedWithoutGames = withoutGames.sorted { $0.rawValue < $1.rawValue } + return [.All] + sortedWithGames + sortedWithoutGames + } } extension DataState: Equatable { diff --git a/score-ios/Views/ListViews/SportSelectorView.swift b/score-ios/Views/ListViews/SportSelectorView.swift index afcdded..f255d06 100644 --- a/score-ios/Views/ListViews/SportSelectorView.swift +++ b/score-ios/Views/ListViews/SportSelectorView.swift @@ -16,7 +16,7 @@ struct SportSelectorView: View { ScrollViewReader { proxy in ScrollView(.horizontal, showsIndicators: false) { HStack { - ForEach(Sport.allCases) { sport in + ForEach(gamesVM.orderSportsByUpcoming(sports: Sport.allCases)) { sport in Button { highlightsVM.selectedSport = sport gamesVM.selectedSport = sport From 9cc147684ce4f9790ee000fdfe017d8befda7887 Mon Sep 17 00:00:00 2001 From: Duru Alayli Date: Wed, 25 Mar 2026 17:58:07 -0400 Subject: [PATCH 2/2] small thing --- score-ios/ViewModels/GamesViewModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/score-ios/ViewModels/GamesViewModel.swift b/score-ios/ViewModels/GamesViewModel.swift index 38e84ab..bfe61cf 100644 --- a/score-ios/ViewModels/GamesViewModel.swift +++ b/score-ios/ViewModels/GamesViewModel.swift @@ -302,7 +302,7 @@ class GamesViewModel: ObservableObject } func orderSportsByUpcoming(sports: [Sport]) -> [Sport] { - let allOtherSports = Sport.allCases.filter { $0 != .All } + let allOtherSports = sports.filter { $0 != .All } let (withGames, withoutGames) = allOtherSports.reduce(into: ([Sport](), [Sport]())) { acc, sport in if allUpcomingGames.contains(where: { $0.sport == sport }) { acc.0.append(sport)