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.
122 lines
3.9 KiB
122 lines
3.9 KiB
//
|
|
// TournamentView.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Razmig Sarkissian on 29/02/2024.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct TournamentView: View {
|
|
@EnvironmentObject var dataStore: DataStore
|
|
@Environment(Tournament.self) var tournament: Tournament
|
|
var presentationContext: PresentationContext = .agenda
|
|
@AppStorage("lastDataSource") var lastDataSource: String?
|
|
|
|
var _lastDataSourceDate: Date? {
|
|
guard let lastDataSource else { return nil }
|
|
return URL.importDateFormatter.date(from: lastDataSource)
|
|
}
|
|
|
|
var body: some View {
|
|
List {
|
|
|
|
if tournament.missingUnrankedValue() {
|
|
Button("update NC") {
|
|
tournament.femaleUnrankedValue = SourceFileManager.shared.getUnrankValue(forMale: false, rankSourceDate: tournament.rankSourceDate)
|
|
tournament.maleUnrankedValue = SourceFileManager.shared.getUnrankValue(forMale: true, rankSourceDate: tournament.rankSourceDate)
|
|
try? dataStore.tournaments.addOrUpdate(instance: tournament)
|
|
}
|
|
}
|
|
|
|
|
|
NavigationLink(value: Screen.inscription) {
|
|
LabeledContent {
|
|
Text(tournament.unsortedTeams().count.formatted())
|
|
} label: {
|
|
Text("Inscriptions")
|
|
}
|
|
|
|
}
|
|
|
|
switch tournament.state() {
|
|
case .initial:
|
|
TournamentInitView()
|
|
case .build:
|
|
TournamentRunningView()
|
|
}
|
|
// InscriptionManagerRowView(tournament: tournament)
|
|
// NavigationLink(value: Screen.groupStage) {
|
|
// Text("Poules")
|
|
// .badge(2)
|
|
// }
|
|
}
|
|
.toolbarBackground(.visible, for: .navigationBar)
|
|
.navigationDestination(for: Screen.self, destination: { screen in
|
|
Group {
|
|
switch screen {
|
|
case .structure:
|
|
TableStructureView()
|
|
case .settings:
|
|
TournamentSettingsView()
|
|
case .inscription:
|
|
InscriptionManagerView(tournament: tournament)
|
|
case .groupStage:
|
|
GroupStagesView()
|
|
}
|
|
}
|
|
.environment(tournament)
|
|
})
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
.toolbar {
|
|
ToolbarItem(placement: .principal) {
|
|
VStack {
|
|
Text(tournament.title()).font(.headline)
|
|
Text(tournament.formattedDate())
|
|
.font(.subheadline).foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
|
|
ToolbarItem(placement: .topBarTrailing) {
|
|
Menu {
|
|
if presentationContext == .agenda {
|
|
Button {
|
|
|
|
} label: {
|
|
Label("Voir dans le gestionnaire", systemImage: "line.diagonal.arrow")
|
|
}
|
|
}
|
|
|
|
Divider()
|
|
if tournament.state() == .build {
|
|
NavigationLink(value: Screen.settings) {
|
|
LabelSettings()
|
|
}
|
|
NavigationLink(value: Screen.structure) {
|
|
LabelStructure()
|
|
}
|
|
}
|
|
} label: {
|
|
LabelOptions()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct InscriptionManagerRowView: View {
|
|
let tournament: Tournament
|
|
var body: some View {
|
|
NavigationLink(value: Screen.inscription) {
|
|
Text("Inscriptions")
|
|
.badge(24)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
NavigationStack {
|
|
TournamentView(presentationContext: .agenda)
|
|
.environment(Tournament.mock())
|
|
}
|
|
}
|
|
|