From ce235319baf268d218aca95d4414e61347aa8fd2 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Wed, 19 Jun 2024 07:35:53 +0200 Subject: [PATCH] fixes --- PadelClub/Data/Tournament.swift | 29 ++-- .../Match/Components/MatchDateView.swift | 15 +- .../Views/Shared/TournamentFilterView.swift | 12 +- .../Tournament/TournamentBuildView.swift | 151 ++++++++++-------- .../Views/Tournament/TournamentView.swift | 2 +- 5 files changed, 125 insertions(+), 84 deletions(-) diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index fe373b6..8e399cd 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -1346,38 +1346,43 @@ class Tournament : ModelObject, Storable { return TournamentStatus(label: label, completion: completionLabel) } - func bracketStatus() async -> String { + func bracketStatus() async -> (status: String, cut: TeamRegistration.TeamRange?) { let availableSeeds = availableSeeds() + let cut = TeamRegistration.TeamRange(availableSeeds.first, availableSeeds.last) if availableSeeds.isEmpty == false { - return "placer \(availableSeeds.count) tête\(availableSeeds.count.pluralSuffix) de série" + return ("placer \(availableSeeds.count) tête\(availableSeeds.count.pluralSuffix) de série", cut) } let availableQualifiedTeams = availableQualifiedTeams() if availableQualifiedTeams.isEmpty == false { - return "placer \(availableQualifiedTeams.count) qualifié" + availableQualifiedTeams.count.pluralSuffix + return ("placer \(availableQualifiedTeams.count) qualifié" + availableQualifiedTeams.count.pluralSuffix, cut) } if let round = getActiveRound() { - return [round.roundTitle(.short), round.roundStatus()].joined(separator: " ") + return ([round.roundTitle(.short), round.roundStatus()].joined(separator: " "), cut) } else { - return "à construire" + return ("à construire", nil) } } - func groupStageStatus() async -> String { - let groupStageTeamsCount = groupStageTeams().count + func groupStageStatus() async -> (status: String, cut: TeamRegistration.TeamRange?) { + let groupStageTeams = groupStageTeams() + let groupStageTeamsCount = groupStageTeams.count if groupStageTeamsCount == 0 || groupStageTeamsCount != groupStageSpots() { - return "à faire" + return ("à faire", nil) } + + let cut = TeamRegistration.TeamRange(groupStageTeams.first, groupStageTeams.last) + let runningGroupStages = groupStages().filter({ $0.isRunning() }) - if groupStagesAreOver() { return "terminées" } + if groupStagesAreOver() { return ("terminées", cut) } if runningGroupStages.isEmpty { let ongoingGroupStages = runningGroupStages.filter({ $0.hasStarted() && $0.hasEnded() == false }) if ongoingGroupStages.isEmpty == false { - return "Poule" + ongoingGroupStages.count.pluralSuffix + " " + ongoingGroupStages.map { ($0.index + 1).formatted() }.joined(separator: ", ") + " en cours" + return ("Poule" + ongoingGroupStages.count.pluralSuffix + " " + ongoingGroupStages.map { ($0.index + 1).formatted() }.joined(separator: ", ") + " en cours", cut) } - return groupStages().count.formatted() + " poule" + groupStages().count.pluralSuffix + return (groupStages().count.formatted() + " poule" + groupStages().count.pluralSuffix, cut) } else { - return "Poule" + runningGroupStages.count.pluralSuffix + " " + runningGroupStages.map { ($0.index + 1).formatted() }.joined(separator: ", ") + " en cours" + return ("Poule" + runningGroupStages.count.pluralSuffix + " " + runningGroupStages.map { ($0.index + 1).formatted() }.joined(separator: ", ") + " en cours", cut) } } diff --git a/PadelClub/Views/Match/Components/MatchDateView.swift b/PadelClub/Views/Match/Components/MatchDateView.swift index 86a7829..653c5b6 100644 --- a/PadelClub/Views/Match/Components/MatchDateView.swift +++ b/PadelClub/Views/Match/Components/MatchDateView.swift @@ -26,17 +26,28 @@ struct MatchDateView: View { var body: some View { Menu { + let estimatedDuration = match.getDuration() if match.startDate == nil && isReady { Button("Démarrer") { match.startDate = Date() match.confirmed = true _save() } - Button("Échauffement") { + Button("Démarrer dans 5 minutes") { match.startDate = Calendar.current.date(byAdding: .minute, value: 5, to: Date()) match.confirmed = true _save() } + Button("Démarrer dans 15 minutes") { + match.startDate = Calendar.current.date(byAdding: .minute, value: 15, to: Date()) + match.confirmed = true + _save() + } + Button("Démarrer dans \(estimatedDuration.formatted()) minutes") { + match.startDate = Calendar.current.date(byAdding: .minute, value: estimatedDuration, to: Date()) + match.confirmed = true + _save() + } } else { if isReady { Button("Démarrer maintenant") { @@ -46,8 +57,6 @@ struct MatchDateView: View { _save() } } else { - let tournament = match.currentTournament() - let estimatedDuration = tournament != nil ? match.matchFormat.getEstimatedDuration(tournament!.additionalEstimationDuration) : match.matchFormat.getEstimatedDuration() Button("Décaler de \(estimatedDuration) minutes") { match.cleanScheduleAndSave(match.startDate?.addingTimeInterval(Double(estimatedDuration) * 60.0)) } diff --git a/PadelClub/Views/Shared/TournamentFilterView.swift b/PadelClub/Views/Shared/TournamentFilterView.swift index 000b035..d9bcb65 100644 --- a/PadelClub/Views/Shared/TournamentFilterView.swift +++ b/PadelClub/Views/Shared/TournamentFilterView.swift @@ -66,7 +66,7 @@ struct TournamentFilterView: View { } } } label: { - Text(level.localizedLabel()) + Text(level.localizedLabel(.title)) } } } header: { @@ -88,7 +88,7 @@ struct TournamentFilterView: View { } } } label: { - Text(category.localizedLabel()) + Text(category.localizedLabel(.title)) } } } header: { @@ -110,8 +110,8 @@ struct TournamentFilterView: View { } } } label: { - Text(category.localizedLabel()) - } + Text(category.localizedLabel(.title)) + } } } header: { Text("Catégories d'âge") @@ -124,6 +124,10 @@ struct TournamentFilterView: View { federalDataViewModel.removeFilters() dismiss() } + } else { + Button("Fermer", role: .cancel) { + dismiss() + } } } ToolbarItem(placement: .topBarTrailing) { diff --git a/PadelClub/Views/Tournament/TournamentBuildView.swift b/PadelClub/Views/Tournament/TournamentBuildView.swift index 976c655..7f4954d 100644 --- a/PadelClub/Views/Tournament/TournamentBuildView.swift +++ b/PadelClub/Views/Tournament/TournamentBuildView.swift @@ -9,8 +9,8 @@ import SwiftUI struct TournamentBuildView: View { var tournament: Tournament - @State private var bracketStatus: String? - @State private var groupStageStatus: String? + @State private var bracketStatus: (status: String, cut: TeamRegistration.TeamRange?)? + @State private var groupStageStatus: (String, TeamRegistration.TeamRange?)? @State private var callStatus: Tournament.TournamentStatus? @State private var scheduleStatus: Tournament.TournamentStatus? @State private var cashierStatus: Tournament.TournamentStatus? @@ -18,7 +18,74 @@ struct TournamentBuildView: View { @ViewBuilder var body: some View { let state = tournament.state() - + + Section { + if tournament.groupStageCount > 0 { + NavigationLink(value: Screen.groupStage) { + LabeledContent { + if let groupStageStatus { + Text(groupStageStatus.0).lineLimit(1) + .multilineTextAlignment(.trailing) + } else { + ProgressView() + } + } label: { + Text("Poules") + if tournament.shouldVerifyGroupStage { + Text("Vérifier les poules").foregroundStyle(.logoRed) + } else if let range = groupStageStatus?.1 { + HStack { + if let left = range.left { + Text(left.weight.formatted()) + } + + if let right = range.right { + Image(systemName: "arrowshape.forward.fill") + Text(right.weight.formatted()) + } + } + } + } + } + .task { + groupStageStatus = await tournament.groupStageStatus() + } + } + + if tournament.rounds().isEmpty == false { + NavigationLink(value: Screen.round) { + LabeledContent { + if let bracketStatus { + Text(bracketStatus.0).lineLimit(1) + .multilineTextAlignment(.trailing) + } else { + ProgressView() + } + } label: { + Text("Tableau") + if tournament.shouldVerifyBracket { + Text("Vérifier la tableau").foregroundStyle(.logoRed) + } else if let range = bracketStatus?.1 { + HStack { + if let left = range.left { + Text(left.weight.formatted()) + } + + if let right = range.right { + Image(systemName: "arrowshape.forward.fill") + Text(right.weight.formatted()) + } + } + } + } + } + .task { + bracketStatus = await tournament.bracketStatus() + } + } + } + + Section { if tournament.hasEnded() { NavigationLink(value: Screen.rankings) { @@ -31,27 +98,6 @@ struct TournamentBuildView: View { TournamentBroadcastRowView(tournament: tournament) } - NavigationLink(value: Screen.cashier) { - let tournamentStatus = cashierStatus - LabeledContent { - if let tournamentStatus { - Text(tournamentStatus.completion) - } else { - ProgressView() - } - } label: { - Text("Encaissement") - if let tournamentStatus { - Text(tournamentStatus.label).lineLimit(1) - } else { - Text(" ") - } - } - } - .task { - cashierStatus = await tournament.cashierStatus() - } - if state != .finished { NavigationLink(value: Screen.schedule) { let tournamentStatus = scheduleStatus @@ -95,49 +141,26 @@ struct TournamentBuildView: View { callStatus = await tournament.callStatus() } } - } - - Section { - if tournament.groupStageCount > 0 { - NavigationLink(value: Screen.groupStage) { - LabeledContent { - if let groupStageStatus { - Text(groupStageStatus).lineLimit(1) - .multilineTextAlignment(.trailing) - } else { - ProgressView() - } - } label: { - Text("Poules") - if tournament.shouldVerifyGroupStage { - Text("Vérifier les poules").foregroundStyle(.logoRed) - } - } - } - .task { - groupStageStatus = await tournament.groupStageStatus() - } - } - if tournament.rounds().isEmpty == false { - NavigationLink(value: Screen.round) { - LabeledContent { - if let bracketStatus { - Text(bracketStatus).lineLimit(1) - .multilineTextAlignment(.trailing) - } else { - ProgressView() - } - } label: { - Text("Tableau") - if tournament.shouldVerifyBracket { - Text("Vérifier la tableau").foregroundStyle(.logoRed) - } + NavigationLink(value: Screen.cashier) { + let tournamentStatus = cashierStatus + LabeledContent { + if let tournamentStatus { + Text(tournamentStatus.completion) + } else { + ProgressView() + } + } label: { + Text("Encaissement") + if let tournamentStatus { + Text(tournamentStatus.label).lineLimit(1) + } else { + Text(" ") } } - .task { - bracketStatus = await tournament.bracketStatus() - } + } + .task { + cashierStatus = await tournament.cashierStatus() } } } diff --git a/PadelClub/Views/Tournament/TournamentView.swift b/PadelClub/Views/Tournament/TournamentView.swift index ebac2b1..c57c363 100644 --- a/PadelClub/Views/Tournament/TournamentView.swift +++ b/PadelClub/Views/Tournament/TournamentView.swift @@ -64,8 +64,8 @@ struct TournamentView: View { Section { TournamentInscriptionView(tournament: tournament) } - TournamentInitView(tournament: tournament) TournamentBuildView(tournament: tournament) + TournamentInitView(tournament: tournament) case .running: TournamentBuildView(tournament: tournament) TournamentRunningView(tournament: tournament)