fix some stuff with match validation and planning match limit view

paca_championship
Raz 1 year ago
parent 5d2a52dce7
commit 91a3ec1700
  1. 10
      PadelClub/Data/Match.swift
  2. 80
      PadelClub/Views/Match/Components/MatchDateView.swift
  3. 4
      PadelClub/Views/Match/MatchDetailView.swift
  4. 9
      PadelClub/Views/Planning/PlanningSettingsView.swift
  5. 19
      PadelClub/Views/Score/EditScoreView.swift
  6. 4
      PadelClub/Views/Score/SetInputView.swift

@ -213,7 +213,7 @@ defer {
func cleanScheduleAndSave(_ targetStartDate: Date? = nil) { func cleanScheduleAndSave(_ targetStartDate: Date? = nil) {
startDate = targetStartDate startDate = targetStartDate
confirmed = targetStartDate == nil ? false : true confirmed = false
endDate = nil endDate = nil
followingMatch()?.cleanScheduleAndSave(nil) followingMatch()?.cleanScheduleAndSave(nil)
_loserMatch()?.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 { if hasEnded() == false {
startDate = fromStartDate startDate = fromStartDate
@ -650,9 +650,11 @@ defer {
startDate = fromStartDate startDate = fromStartDate
endDate = toEndDate endDate = toEndDate
} }
if hasStarted() { if let startDate, startDate.timeIntervalSinceNow <= 300 {
confirmed = true confirmed = true
} else {
confirmed = false
} }
} }

@ -34,41 +34,8 @@ struct MatchDateView: View {
} else { } else {
Menu { Menu {
let estimatedDuration = match.getDuration() let estimatedDuration = match.getDuration()
if match.startDate == nil && isReady { if isReady && match.hasStarted() == false {
Button("Démarrer") { Section {
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 {
Button("Démarrer maintenant") { Button("Démarrer maintenant") {
if let updatedField { if let updatedField {
match.setCourt(updatedField) match.setCourt(updatedField)
@ -78,18 +45,51 @@ struct MatchDateView: View {
match.confirmed = true match.confirmed = true
_save() _save()
} }
} else { Button("Démarrer dans 5 minutes") {
Button("Décaler de \(estimatedDuration) minutes") {
if let updatedField { if let updatedField {
match.setCourt(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") { } else {
match.cleanScheduleAndSave() 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: {
label label
} }

@ -183,7 +183,9 @@ struct MatchDetailView: View {
}) })
.sheet(item: $scoreType, onDismiss: { .sheet(item: $scoreType, onDismiss: {
if match.hasEnded() { 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 presentRanking = true
} else { } else {
presentFollowUpMatch = true presentFollowUpMatch = true

@ -496,14 +496,19 @@ struct PlanningSettingsView: View {
.font(.title3) .font(.title3)
.foregroundStyle(error ? .red : .green) .foregroundStyle(error ? .red : .green)
} label: { } label: {
let label = "\(count) match\(count.pluralSuffix) en \(matchFormat.format)" let label : String = "\(count) match\(count.pluralSuffix) en \(matchFormat.format)"
let subtitle = "pas plus de " + totalForThisFormat.formatted() + " match\(totalForThisFormat.pluralSuffix) pour ce jour" 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(label)
Text(subtitle) Text(subtitle)
} }
} }
} header: { } header: {
Text(date.formatted(.dateTime.weekday(.abbreviated).day(.twoDigits).month(.abbreviated))) 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.")
} }
} }
} }

@ -45,7 +45,9 @@ struct EditScoreView: View {
@ObservedObject var matchDescriptor: MatchDescriptor @ObservedObject var matchDescriptor: MatchDescriptor
@Environment(\.dismiss) private var dismiss @Environment(\.dismiss) private var dismiss
@State private var showSetInputView: Bool = true
@State private var showTieBreakInputView: Bool = false
let colorTeamOne: Color = .mint let colorTeamOne: Color = .mint
let colorTeamTwo: Color = .cyan let colorTeamTwo: Color = .cyan
@ -81,7 +83,7 @@ struct EditScoreView: View {
.bold() .bold()
} }
} }
.listRowView(isActive: true, color: colorTeamOne, hideColorVariation: true) .listRowView(isActive: teamOneSetupIsActive, color: .master, hideColorVariation: false)
HStack { HStack {
Spacer() Spacer()
VStack(alignment: .trailing) { 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: { } footer: {
HStack { HStack {
Menu { Menu {
@ -120,7 +122,7 @@ struct EditScoreView: View {
} }
} }
ForEach($matchDescriptor.setDescriptors) { $setDescriptor in ForEach($matchDescriptor.setDescriptors) { $setDescriptor in
SetInputView(setDescriptor: $setDescriptor) SetInputView(setDescriptor: $setDescriptor, showSetInputView: $showSetInputView, showTieBreakInputView: $showTieBreakInputView)
.onChange(of: setDescriptor.hasEnded) { .onChange(of: setDescriptor.hasEnded) {
if setDescriptor.hasEnded { if setDescriptor.hasEnded {
if matchDescriptor.hasEnded == false { if matchDescriptor.hasEnded == false {
@ -131,7 +133,7 @@ struct EditScoreView: View {
matchDescriptor.setDescriptors = Array(matchDescriptor.setDescriptors[0...index]) matchDescriptor.setDescriptors = Array(matchDescriptor.setDescriptors[0...index])
} }
} }
.tint(getColor()) .tint(.master)
} }
if matchDescriptor.hasEnded { if matchDescriptor.hasEnded {
@ -180,6 +182,10 @@ struct EditScoreView: View {
var teamOneSetupIsActive: Bool { var teamOneSetupIsActive: Bool {
if matchDescriptor.hasEnded && showSetInputView == false && showTieBreakInputView == false {
return false
}
guard let setDescriptor = matchDescriptor.setDescriptors.last else { guard let setDescriptor = matchDescriptor.setDescriptors.last else {
return false return false
} }
@ -197,6 +203,9 @@ struct EditScoreView: View {
} }
var teamTwoSetupIsActive: Bool { var teamTwoSetupIsActive: Bool {
if matchDescriptor.hasEnded && showSetInputView == false && showTieBreakInputView == false {
return false
}
guard let setDescriptor = matchDescriptor.setDescriptors.last else { guard let setDescriptor = matchDescriptor.setDescriptors.last else {
return false return false
} }

@ -9,8 +9,8 @@ import SwiftUI
struct SetInputView: View { struct SetInputView: View {
@Binding var setDescriptor: SetDescriptor @Binding var setDescriptor: SetDescriptor
@State private var showSetInputView: Bool = true @Binding var showSetInputView: Bool
@State private var showTieBreakInputView: Bool = false @Binding var showTieBreakInputView: Bool
var setFormat: SetFormat { setDescriptor.setFormat } var setFormat: SetFormat { setDescriptor.setFormat }

Loading…
Cancel
Save