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.
92 lines
3.4 KiB
92 lines
3.4 KiB
//
|
|
// EventTournamentsView.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Razmig Sarkissian on 17/05/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
import LeStorage
|
|
|
|
struct EventTournamentsView: View {
|
|
@EnvironmentObject var dataStore: DataStore
|
|
@Environment(NavigationViewModel.self) private var navigation
|
|
let event: Event
|
|
@State private var newTournament: Tournament?
|
|
|
|
var presentTournamentCreationView: Binding<Bool> { Binding(
|
|
get: { newTournament != nil },
|
|
set: { isPresented in
|
|
if isPresented == false {
|
|
newTournament = nil
|
|
}
|
|
}
|
|
)}
|
|
|
|
var body: some View {
|
|
let tournaments = event.tournaments
|
|
List {
|
|
ForEach(tournaments) { tournament in
|
|
NavigationLink {
|
|
TournamentStatusView(tournament: tournament, eventDismiss: true)
|
|
} label: {
|
|
TournamentCellView(tournament: tournament)
|
|
.contextMenu {
|
|
Button {
|
|
navigation.openTournamentInOrganizer(tournament)
|
|
} label: {
|
|
Label("Voir dans le gestionnaire", systemImage: "line.diagonal.arrow")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.toolbar {
|
|
ToolbarItem(placement: .topBarTrailing) {
|
|
BarButtonView("Ajouter un tournoi", icon: "plus.circle.fill") {
|
|
let tournament = Tournament.newEmptyInstance()
|
|
newTournament = tournament
|
|
}
|
|
}
|
|
}
|
|
.headerProminence(.increased)
|
|
.sheet(isPresented: presentTournamentCreationView) {
|
|
if let newTournament {
|
|
NavigationStack {
|
|
List {
|
|
Section {
|
|
TournamentConfigurationView(tournament: newTournament)
|
|
}
|
|
Section {
|
|
RowButtonView("Ajouter le tournoi") {
|
|
newTournament.event = event.id
|
|
newTournament.courtCount = event.eventCourtCount()
|
|
newTournament.startDate = event.eventStartDate()
|
|
newTournament.dayDuration = event.eventDayDuration()
|
|
newTournament.setupFederalSettings(fromEvent: event)
|
|
|
|
do {
|
|
try dataStore.tournaments.addOrUpdate(instance: newTournament)
|
|
} catch {
|
|
Logger.error(error)
|
|
}
|
|
|
|
self.newTournament = nil
|
|
}
|
|
}
|
|
}
|
|
.toolbarBackground(.visible, for: .navigationBar)
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.navigationTitle("Nouveau tournoi")
|
|
.toolbar {
|
|
ToolbarItem(placement: .cancellationAction) {
|
|
Button("Annuler", role: .cancel) {
|
|
self.newTournament = nil
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|