From 91a3ec170003577c151f2f689318422f441f6b84 Mon Sep 17 00:00:00 2001 From: Raz Date: Mon, 14 Oct 2024 11:35:42 +0200 Subject: [PATCH] fix some stuff with match validation and planning match limit view --- PadelClub/Data/Match.swift | 10 ++- .../Match/Components/MatchDateView.swift | 80 +++++++++---------- PadelClub/Views/Match/MatchDetailView.swift | 4 +- .../Views/Planning/PlanningSettingsView.swift | 9 ++- PadelClub/Views/Score/EditScoreView.swift | 19 +++-- PadelClub/Views/Score/SetInputView.swift | 4 +- 6 files changed, 72 insertions(+), 54 deletions(-) diff --git a/PadelClub/Data/Match.swift b/PadelClub/Data/Match.swift index 9a92f61..f3570f6 100644 --- a/PadelClub/Data/Match.swift +++ b/PadelClub/Data/Match.swift @@ -213,7 +213,7 @@ defer { func cleanScheduleAndSave(_ targetStartDate: Date? = nil) { startDate = targetStartDate - confirmed = targetStartDate == nil ? false : true + confirmed = false endDate = nil followingMatch()?.cleanScheduleAndSave(nil) _loserMatch()?.cleanScheduleAndSave(nil) @@ -629,7 +629,7 @@ defer { } } - func validateMatch(fromStartDate: Date, toEndDate: Date, fieldSetup: MatchFieldSetup) { + func validateMatch(fromStartDate: Date, toEndDate: Date, fieldSetup: MatchFieldSetup, forced: Bool = false) { if hasEnded() == false { startDate = fromStartDate @@ -650,9 +650,11 @@ defer { startDate = fromStartDate endDate = toEndDate } - - if hasStarted() { + + if let startDate, startDate.timeIntervalSinceNow <= 300 { confirmed = true + } else { + confirmed = false } } diff --git a/PadelClub/Views/Match/Components/MatchDateView.swift b/PadelClub/Views/Match/Components/MatchDateView.swift index 7c37d38..f64f8bb 100644 --- a/PadelClub/Views/Match/Components/MatchDateView.swift +++ b/PadelClub/Views/Match/Components/MatchDateView.swift @@ -34,41 +34,8 @@ struct MatchDateView: View { } else { Menu { let estimatedDuration = match.getDuration() - if match.startDate == nil && isReady { - Button("Démarrer") { - if let updatedField { - match.setCourt(updatedField) - } - match.startDate = Date() - match.confirmed = true - _save() - } - Button("Démarrer dans 5 minutes") { - if let updatedField { - match.setCourt(updatedField) - } - match.startDate = Calendar.current.date(byAdding: .minute, value: 5, to: Date()) - match.confirmed = true - _save() - } - Button("Démarrer dans 15 minutes") { - if let updatedField { - match.setCourt(updatedField) - } - match.startDate = Calendar.current.date(byAdding: .minute, value: 15, to: Date()) - match.confirmed = true - _save() - } - Button("Démarrer dans \(estimatedDuration.formatted()) minutes") { - if let updatedField { - match.setCourt(updatedField) - } - match.startDate = Calendar.current.date(byAdding: .minute, value: estimatedDuration, to: Date()) - match.confirmed = true - _save() - } - } else { - if isReady { + if isReady && match.hasStarted() == false { + Section { Button("Démarrer maintenant") { if let updatedField { match.setCourt(updatedField) @@ -78,18 +45,51 @@ struct MatchDateView: View { match.confirmed = true _save() } - } else { - Button("Décaler de \(estimatedDuration) minutes") { + Button("Démarrer dans 5 minutes") { if let updatedField { match.setCourt(updatedField) } - match.cleanScheduleAndSave(match.startDate?.addingTimeInterval(Double(estimatedDuration) * 60.0)) + match.startDate = Calendar.current.date(byAdding: .minute, value: 5, to: Date()) + match.endDate = nil + match.confirmed = true + _save() } + Button("Démarrer dans 15 minutes") { + if let updatedField { + match.setCourt(updatedField) + } + match.startDate = Calendar.current.date(byAdding: .minute, value: 15, to: Date()) + match.endDate = nil + match.confirmed = true + _save() + } + Button("Démarrer dans \(estimatedDuration.formatted()) minutes") { + if let updatedField { + match.setCourt(updatedField) + } + match.startDate = Calendar.current.date(byAdding: .minute, value: estimatedDuration, to: Date()) + match.endDate = nil + match.confirmed = true + _save() + } + } header: { + Text("Le match apparaîtra dans les en cours") } - Button("Retirer l'horaire") { - match.cleanScheduleAndSave() + } else { + Button("Décaler de \(estimatedDuration) minutes") { + if let updatedField { + match.setCourt(updatedField) + } + match.cleanScheduleAndSave(match.startDate?.addingTimeInterval(Double(estimatedDuration) * 60.0)) } } + Button("Indiquer un score") { + + } + Divider() + Button("Retirer l'horaire") { + match.cleanScheduleAndSave() + } } label: { label } diff --git a/PadelClub/Views/Match/MatchDetailView.swift b/PadelClub/Views/Match/MatchDetailView.swift index b1c1fe3..ba73ef8 100644 --- a/PadelClub/Views/Match/MatchDetailView.swift +++ b/PadelClub/Views/Match/MatchDetailView.swift @@ -183,7 +183,9 @@ struct MatchDetailView: View { }) .sheet(item: $scoreType, onDismiss: { if match.hasEnded() { - if match.index == 0, match.roundObject?.parent == nil { + if match.index == 0, match.isGroupStage() == false, match.roundObject?.parent == nil { + presentRanking = true + } else if match.isGroupStage(), match.currentTournament()?.hasEnded() == true { presentRanking = true } else { presentFollowUpMatch = true diff --git a/PadelClub/Views/Planning/PlanningSettingsView.swift b/PadelClub/Views/Planning/PlanningSettingsView.swift index 5eeef89..53feb6d 100644 --- a/PadelClub/Views/Planning/PlanningSettingsView.swift +++ b/PadelClub/Views/Planning/PlanningSettingsView.swift @@ -496,14 +496,19 @@ struct PlanningSettingsView: View { .font(.title3) .foregroundStyle(error ? .red : .green) } label: { - let label = "\(count) match\(count.pluralSuffix) en \(matchFormat.format)" - let subtitle = "pas plus de " + totalForThisFormat.formatted() + " match\(totalForThisFormat.pluralSuffix) pour ce jour" + let label : String = "\(count) match\(count.pluralSuffix) en \(matchFormat.format)" + let optionA : String = "aucun match possible à ce format" + let optionB : String = "max " + totalForThisFormat.formatted() + "/\(totalMatches) match\(totalForThisFormat.pluralSuffix) à ce format" + let subtitle : String = (totalForThisFormat == 0) ? optionA : optionB Text(label) Text(subtitle) } } } header: { Text(date.formatted(.dateTime.weekday(.abbreviated).day(.twoDigits).month(.abbreviated))) + } footer: { + let totalMatches = countedSet.totalCount() + Text("Une équipe jouera potentiellement jusqu'à \(totalMatches) match\(totalMatches.pluralSuffix) ce jour.") } } } diff --git a/PadelClub/Views/Score/EditScoreView.swift b/PadelClub/Views/Score/EditScoreView.swift index 06eb65c..a080a03 100644 --- a/PadelClub/Views/Score/EditScoreView.swift +++ b/PadelClub/Views/Score/EditScoreView.swift @@ -45,7 +45,9 @@ struct EditScoreView: View { @ObservedObject var matchDescriptor: MatchDescriptor @Environment(\.dismiss) private var dismiss - + @State private var showSetInputView: Bool = true + @State private var showTieBreakInputView: Bool = false + let colorTeamOne: Color = .mint let colorTeamTwo: Color = .cyan @@ -81,7 +83,7 @@ struct EditScoreView: View { .bold() } } - .listRowView(isActive: true, color: colorTeamOne, hideColorVariation: true) + .listRowView(isActive: teamOneSetupIsActive, color: .master, hideColorVariation: false) HStack { Spacer() VStack(alignment: .trailing) { @@ -92,7 +94,7 @@ struct EditScoreView: View { } } } - .listRowView(isActive: true, color: colorTeamTwo, hideColorVariation: true, alignment: .trailing) + .listRowView(isActive: teamTwoSetupIsActive, color: .master, hideColorVariation: false, alignment: .trailing) } footer: { HStack { Menu { @@ -120,7 +122,7 @@ struct EditScoreView: View { } } ForEach($matchDescriptor.setDescriptors) { $setDescriptor in - SetInputView(setDescriptor: $setDescriptor) + SetInputView(setDescriptor: $setDescriptor, showSetInputView: $showSetInputView, showTieBreakInputView: $showTieBreakInputView) .onChange(of: setDescriptor.hasEnded) { if setDescriptor.hasEnded { if matchDescriptor.hasEnded == false { @@ -131,7 +133,7 @@ struct EditScoreView: View { matchDescriptor.setDescriptors = Array(matchDescriptor.setDescriptors[0...index]) } } - .tint(getColor()) + .tint(.master) } if matchDescriptor.hasEnded { @@ -180,6 +182,10 @@ struct EditScoreView: View { var teamOneSetupIsActive: Bool { + if matchDescriptor.hasEnded && showSetInputView == false && showTieBreakInputView == false { + return false + } + guard let setDescriptor = matchDescriptor.setDescriptors.last else { return false } @@ -197,6 +203,9 @@ struct EditScoreView: View { } var teamTwoSetupIsActive: Bool { + if matchDescriptor.hasEnded && showSetInputView == false && showTieBreakInputView == false { + return false + } guard let setDescriptor = matchDescriptor.setDescriptors.last else { return false } diff --git a/PadelClub/Views/Score/SetInputView.swift b/PadelClub/Views/Score/SetInputView.swift index 504710e..4fbbb64 100644 --- a/PadelClub/Views/Score/SetInputView.swift +++ b/PadelClub/Views/Score/SetInputView.swift @@ -9,8 +9,8 @@ import SwiftUI struct SetInputView: View { @Binding var setDescriptor: SetDescriptor - @State private var showSetInputView: Bool = true - @State private var showTieBreakInputView: Bool = false + @Binding var showSetInputView: Bool + @Binding var showTieBreakInputView: Bool var setFormat: SetFormat { setDescriptor.setFormat }