add a way to filter out tournament in ongoing view

main
Razmig Sarkissian 2 weeks ago
parent 00d759dd6c
commit 4d366b437d
  1. 48
      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<String> = 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<Match>] = [.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")
}
}
}

Loading…
Cancel
Save