You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.6 KiB
79 lines
2.6 KiB
//
|
|
// EventListView.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Razmig Sarkissian on 29/02/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct EventListView: View {
|
|
@EnvironmentObject var dataStore: DataStore
|
|
|
|
let tournaments: [FederalTournamentHolder]
|
|
let viewStyle: AgendaDestination.ViewStyle
|
|
|
|
var body: some View {
|
|
let groupedTournamentsByDate = Dictionary(grouping: tournaments) { $0.startDate.startOfMonth }
|
|
|
|
ForEach(groupedTournamentsByDate.keys.sorted(by: <), id: \.self) { section in
|
|
if let _tournaments = groupedTournamentsByDate[section]?.sorted(by: \.startDate) {
|
|
Section {
|
|
switch viewStyle {
|
|
case .list:
|
|
_listView(_tournaments)
|
|
case .calendar:
|
|
CalendarView(date: section, tournaments: _tournaments)
|
|
}
|
|
} header: {
|
|
HStack {
|
|
Text(section.monthYearFormatted)
|
|
Spacer()
|
|
let count = _tournaments.map { $0.tournaments.count }.reduce(0,+)
|
|
Text("\(count.formatted()) tournoi" + count.pluralSuffix)
|
|
}
|
|
}
|
|
.headerProminence(.increased)
|
|
}
|
|
}
|
|
}
|
|
|
|
private func _listView(_ tournaments: [FederalTournamentHolder]) -> some View {
|
|
ForEach(tournaments, id: \.holderId) { tournamentHolder in
|
|
if let tournament = tournamentHolder as? Tournament {
|
|
_tournamentView(tournament)
|
|
} else if let federalTournament = tournamentHolder as? FederalTournament {
|
|
_federalTournamentView(federalTournament)
|
|
}
|
|
}
|
|
}
|
|
|
|
private func _tournamentView(_ tournament: Tournament) -> some View {
|
|
NavigationLink(value: tournament) {
|
|
TournamentCellView(tournament: tournament)
|
|
}
|
|
.swipeActions(edge: .trailing, allowsFullSwipe: true) {
|
|
Button(role: .destructive) {
|
|
try? dataStore.tournaments.delete(instance: tournament)
|
|
} label: {
|
|
LabelDelete()
|
|
}
|
|
}
|
|
.contextMenu {
|
|
Button {
|
|
|
|
} label: {
|
|
Label("Voir dans le gestionnaire", systemImage: "line.diagonal.arrow")
|
|
}
|
|
}
|
|
}
|
|
|
|
private func _federalTournamentView(_ federalTournament: FederalTournament) -> some View {
|
|
TournamentCellView(tournament: federalTournament)
|
|
}
|
|
|
|
}
|
|
|
|
#Preview {
|
|
EventListView(tournaments: [], viewStyle: .calendar)
|
|
}
|
|
|