From 4d366b437d5cf9536a32ae3cedda85e08de8e867 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Wed, 29 Oct 2025 12:56:36 +0100 Subject: [PATCH] add a way to filter out tournament in ongoing view --- .../Ongoing/OngoingContainerView.swift | 48 +++++++++++-------- 1 file changed, 29 insertions(+), 19 deletions(-) diff --git a/PadelClub/Views/Navigation/Ongoing/OngoingContainerView.swift b/PadelClub/Views/Navigation/Ongoing/OngoingContainerView.swift index dfcc058..bc53bc7 100644 --- a/PadelClub/Views/Navigation/Ongoing/OngoingContainerView.swift +++ b/PadelClub/Views/Navigation/Ongoing/OngoingContainerView.swift @@ -16,6 +16,15 @@ class OngoingViewModel { var destination: OngoingDestination? = .running var hideUnconfirmedMatches: Bool = false var hideNotReadyMatches: Bool = false + var selectedTournaments: Set = Set() { + didSet { + DataStore.shared.resetOngoingCache() + } + } + + func tournaments() -> [Tournament] { + Set(DataStore.shared.runningAndNextMatches().compactMap({ $0.currentTournament() })).sorted(by: \.startDate) + } func areFiltersEnabled() -> Bool { hideUnconfirmedMatches || hideNotReadyMatches @@ -24,7 +33,7 @@ class OngoingViewModel { let defaultSorting : [MySortDescriptor] = [.keyPath(\Match.startDate!), .keyPath(\Match.index), .keyPath(\Match.courtIndexForSorting)] var runningAndNextMatches: [Match] { - DataStore.shared.runningAndNextMatches().sorted(using: defaultSorting, order: .ascending) + DataStore.shared.runningAndNextMatches(selectedTournaments).sorted(using: defaultSorting, order: .ascending) } var filteredRunningAndNextMatches: [Match] { @@ -57,32 +66,33 @@ struct OngoingContainerView: View { .toolbarBackground(.visible, for: .navigationBar) .navigationTitle("Programmation") .toolbar { - if ongoingViewModel.destination == .followUp { - ToolbarItem(placement: .topBarLeading) { - Menu { + ToolbarItem(placement: .topBarLeading) { + Menu { + NavigationLink { + List(selection: $ongoingViewModel.selectedTournaments) { + ForEach(ongoingViewModel.tournaments()) { tournament in + TournamentCellView(tournament: tournament) + .tag(tournament.id) + } + } + .environment(\.editMode, Binding.constant(EditMode.active)) + .navigationTitle("Tournois visibles") + .navigationBarTitleDisplayMode(.inline) + .toolbarBackground(.visible, for: .navigationBar) + } label: { + Label("Tournois visibles", systemImage: "circle.grid.2x2.topleft.checkmark.filled") + } + if ongoingViewModel.destination == .followUp { + Divider() Toggle(isOn: $ongoingViewModel.hideUnconfirmedMatches) { Text("masquer non confirmés") } Toggle(isOn: $ongoingViewModel.hideNotReadyMatches) { Text("masquer incomplets") } - } label: { - Image(systemName: "line.3.horizontal.decrease.circle") - .resizable() - .scaledToFit() - .frame(minHeight: 32) } - .symbolVariant(ongoingViewModel.areFiltersEnabled() ? .fill : .none) - } - } - ToolbarItem(placement: .topBarTrailing) { - Button { - showMatchPicker = true } label: { - Image(systemName: "rectangle.stack.badge.plus") - .resizable() - .scaledToFit() - .frame(minHeight: 32) + Image(systemName: "line.3.horizontal.decrease") } } }