fix some stuff with match validation and planning match limit view

paca_championship
Raz 1 year ago
parent 5d2a52dce7
commit 91a3ec1700
  1. 8
      PadelClub/Data/Match.swift
  2. 26
      PadelClub/Views/Match/Components/MatchDateView.swift
  3. 4
      PadelClub/Views/Match/MatchDetailView.swift
  4. 9
      PadelClub/Views/Planning/PlanningSettingsView.swift
  5. 17
      PadelClub/Views/Score/EditScoreView.swift
  6. 4
      PadelClub/Views/Score/SetInputView.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
@ -651,8 +651,10 @@ defer {
endDate = toEndDate
}
if hasStarted() {
if let startDate, startDate.timeIntervalSinceNow <= 300 {
confirmed = true
} else {
confirmed = false
}
}

@ -34,12 +34,14 @@ struct MatchDateView: View {
} else {
Menu {
let estimatedDuration = match.getDuration()
if match.startDate == nil && isReady {
Button("Démarrer") {
if isReady && match.hasStarted() == false {
Section {
Button("Démarrer maintenant") {
if let updatedField {
match.setCourt(updatedField)
}
match.startDate = Date()
match.endDate = nil
match.confirmed = true
_save()
}
@ -48,6 +50,7 @@ struct MatchDateView: View {
match.setCourt(updatedField)
}
match.startDate = Calendar.current.date(byAdding: .minute, value: 5, to: Date())
match.endDate = nil
match.confirmed = true
_save()
}
@ -56,6 +59,7 @@ struct MatchDateView: View {
match.setCourt(updatedField)
}
match.startDate = Calendar.current.date(byAdding: .minute, value: 15, to: Date())
match.endDate = nil
match.confirmed = true
_save()
}
@ -64,20 +68,13 @@ struct MatchDateView: View {
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") {
if let updatedField {
match.setCourt(updatedField)
}
match.startDate = Date()
match.endDate = nil
match.confirmed = true
_save()
}
} header: {
Text("Le match apparaîtra dans les en cours")
}
} else {
Button("Décaler de \(estimatedDuration) minutes") {
if let updatedField {
@ -86,10 +83,13 @@ struct MatchDateView: View {
match.cleanScheduleAndSave(match.startDate?.addingTimeInterval(Double(estimatedDuration) * 60.0))
}
}
Button("Indiquer un score") {
}
Divider()
Button("Retirer l'horaire") {
match.cleanScheduleAndSave()
}
}
} label: {
label
}

@ -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

@ -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.")
}
}
}

@ -45,6 +45,8 @@ 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
}

@ -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 }

Loading…
Cancel
Save