fix tournaments sorting

multistore
Razmig Sarkissian 1 year ago
parent 4fece3c67e
commit 3bdefc2511
  1. 8
      PadelClub/Views/Navigation/Agenda/ActivityView.swift
  2. 8
      PadelClub/Views/Navigation/Agenda/EventListView.swift

@ -25,13 +25,11 @@ struct ActivityView: View {
var runningTournaments: [FederalTournamentHolder] { var runningTournaments: [FederalTournamentHolder] {
dataStore.tournaments.filter({ $0.endDate == nil }) dataStore.tournaments.filter({ $0.endDate == nil })
.filter({ federalDataViewModel.isTournamentValidForFilters($0) }) .filter({ federalDataViewModel.isTournamentValidForFilters($0) })
.sorted(using: SortDescriptor(\.startDate))
} }
var endedTournaments: [Tournament] { var endedTournaments: [Tournament] {
dataStore.tournaments.filter({ $0.endDate != nil }) dataStore.tournaments.filter({ $0.endDate != nil })
.filter({ federalDataViewModel.isTournamentValidForFilters($0) }) .filter({ federalDataViewModel.isTournamentValidForFilters($0) })
.sorted(using: SortDescriptor(\.startDate, order: .reverse))
} }
// //
// func _activityStatus() -> String? { // func _activityStatus() -> String? {
@ -64,11 +62,11 @@ struct ActivityView: View {
List { List {
switch navigation.agendaDestination! { switch navigation.agendaDestination! {
case .activity: case .activity:
EventListView(tournaments: runningTournaments, viewStyle: viewStyle) EventListView(tournaments: runningTournaments, viewStyle: viewStyle, sortAscending: true)
case .history: case .history:
EventListView(tournaments: endedTournaments, viewStyle: viewStyle) EventListView(tournaments: endedTournaments, viewStyle: viewStyle, sortAscending: false)
case .tenup: case .tenup:
EventListView(tournaments: federalDataViewModel.federalTournaments, viewStyle: viewStyle) EventListView(tournaments: federalDataViewModel.federalTournaments, viewStyle: viewStyle, sortAscending: true)
.id(uuid) .id(uuid)
} }
} }

@ -15,13 +15,15 @@ struct EventListView: View {
let tournaments: [FederalTournamentHolder] let tournaments: [FederalTournamentHolder]
let viewStyle: AgendaDestination.ViewStyle let viewStyle: AgendaDestination.ViewStyle
let sortAscending: Bool
var body: some View { var body: some View {
let groupedTournamentsByDate = Dictionary(grouping: navigation.agendaDestination == .tenup ? federalDataViewModel.filteredFederalTournaments : tournaments) { $0.startDate.startOfMonth } let groupedTournamentsByDate = Dictionary(grouping: navigation.agendaDestination == .tenup ? federalDataViewModel.filteredFederalTournaments : tournaments) { $0.startDate.startOfMonth }
switch viewStyle { switch viewStyle {
case .list: case .list:
ForEach(Array(groupedTournamentsByDate.keys), id: \.self) { section in ForEach(groupedTournamentsByDate.keys.sorted(by: sortAscending ? { $0 < $1 } : { $0 > $1 }), id: \.self) { section in
if let _tournaments = groupedTournamentsByDate[section] { if let _tournaments = groupedTournamentsByDate[section]?.sorted(by: sortAscending ? { $0.startDate < $1.startDate } : { $0.startDate > $1.startDate }
) {
Section { Section {
_listView(_tournaments) _listView(_tournaments)
} header: { } header: {
@ -117,5 +119,5 @@ struct EventListView: View {
} }
#Preview { #Preview {
EventListView(tournaments: [], viewStyle: .calendar) EventListView(tournaments: [], viewStyle: .calendar, sortAscending: true)
} }

Loading…
Cancel
Save