fix planning by court contentunavailable

add some warnings in tablestructure
sync2
Raz 1 year ago
parent 4c5459ed6a
commit 5f35af7fb2
  1. 34
      PadelClub/Views/Planning/PlanningByCourtView.swift
  2. 21
      PadelClub/Views/Tournament/Screen/TableStructureView.swift

@ -43,13 +43,16 @@ struct PlanningByCourtView: View {
_selectedDay = State(wrappedValue: startDate) _selectedDay = State(wrappedValue: startDate)
} }
@ViewBuilder
var body: some View { var body: some View {
let noStartDate = matches.allSatisfy({ $0.startDate == nil })
List { List {
_byCourtView() _byCourtView(noStartDate: noStartDate)
.id(selectedCourt) .id(selectedCourt)
} }
.overlay { .overlay {
if matches.allSatisfy({ $0.startDate == nil }) { if noStartDate {
ContentUnavailableView { ContentUnavailableView {
Label("Aucun horaire défini", systemImage: "clock.badge.questionmark") Label("Aucun horaire défini", systemImage: "clock.badge.questionmark")
} description: { } description: {
@ -59,13 +62,6 @@ struct PlanningByCourtView: View {
selectedScheduleDestination = nil selectedScheduleDestination = nil
} }
} }
} else if courtSlots.isEmpty == false {
ContentUnavailableView {
Label("Aucun match plannifié", systemImage: "clock.badge.questionmark")
} description: {
Text("Aucun match n'a été plannifié sur ce terrain et au jour sélectionné")
} actions: {
}
} }
} }
.navigationTitle(Text(selectedDay.formatted(.dateTime.day().weekday().month()))) .navigationTitle(Text(selectedDay.formatted(.dateTime.day().weekday().month())))
@ -87,7 +83,7 @@ struct PlanningByCourtView: View {
Picker(selection: $selectedCourt) { Picker(selection: $selectedCourt) {
ForEach(courts, id: \.self) { courtIndex in ForEach(courts, id: \.self) { courtIndex in
if courtIndex == Int.max { if courtIndex == Int.max {
Image(systemName: "rectangle.slash").tag(Int.max) Label("Sans terrain", systemImage: "rectangle.slash").tag(Int.max)
} else { } else {
Text(tournament.courtName(atIndex: courtIndex)).tag(courtIndex) Text(tournament.courtName(atIndex: courtIndex)).tag(courtIndex)
} }
@ -102,9 +98,10 @@ struct PlanningByCourtView: View {
} }
@ViewBuilder @ViewBuilder
func _byCourtView() -> some View { func _byCourtView(noStartDate: Bool) -> some View {
if let _matches = courtSlots[selectedCourt]?.filter({ $0.startDate?.dayInt == selectedDay.dayInt }) { if let _matches = courtSlots[selectedCourt]?.filter({ $0.startDate?.dayInt == selectedDay.dayInt }) {
let _sortedMatches = _matches.sorted(by: \.computedStartDateForSorting) let _sortedMatches = _matches.sorted(by: \.computedStartDateForSorting)
if _sortedMatches.isEmpty == false {
ForEach(_sortedMatches.indices, id: \.self) { index in ForEach(_sortedMatches.indices, id: \.self) { index in
let match = _sortedMatches[index] let match = _sortedMatches[index]
Section { Section {
@ -126,6 +123,21 @@ struct PlanningByCourtView: View {
} }
.headerProminence(.increased) .headerProminence(.increased)
} }
} else if noStartDate == false {
ContentUnavailableView {
Label("Aucun match plannifié", systemImage: "clock.badge.questionmark")
} description: {
Text("Aucun match n'a été plannifié sur ce terrain et au jour sélectionné")
} actions: {
}
}
} else if noStartDate == false {
ContentUnavailableView {
Label("Aucun match plannifié", systemImage: "clock.badge.questionmark")
} description: {
Text("Aucun match n'a été plannifié sur ce terrain et au jour sélectionné")
} actions: {
}
} }
} }

@ -49,6 +49,11 @@ struct TableStructureView: View {
teamCount / max(1, teamsPerGroupStage) teamCount / max(1, teamsPerGroupStage)
} }
var tsPure: Int {
max(teamCount - groupStageCount * teamsPerGroupStage, 0)
}
@ViewBuilder @ViewBuilder
var body: some View { var body: some View {
List { List {
@ -191,12 +196,14 @@ struct TableStructureView: View {
} }
if structurePreset == .manual { if structurePreset == .manual {
LabeledContent { LabeledContent {
let tsPure = max(teamCount - groupStageCount * teamsPerGroupStage, 0)
Text(tsPure.formatted()) Text(tsPure.formatted())
} label: { } label: {
Text("Nombre de têtes de série") Text("Nombre de têtes de série")
if tsPure > 0 && (tsPure > teamCount / 2 || tsPure < teamCount / 8 || tsPure < qualifiedFromGroupStage + groupStageAdditionalQualified) {
Text("Attention !").foregroundStyle(.red)
}
} }
LabeledContent { LabeledContent {
Text(tf.formatted()) Text(tf.formatted())
@ -212,6 +219,16 @@ struct TableStructureView: View {
Text("Total de matchs") Text("Total de matchs")
} }
} }
} footer: {
if tsPure > 0 && structurePreset == .manual {
if tsPure > teamCount / 2 {
Text("Le nombre de têtes de série ne devrait pas être supérieur à la moitié de l'effectif").foregroundStyle(.red)
} else if tsPure < teamCount / 8 {
Text("À partir du moment où vous avez des têtes de série, leur nombre ne devrait pas être inférieur à 1/8ème de l'effectif").foregroundStyle(.red)
} else if tsPure < qualifiedFromGroupStage + groupStageAdditionalQualified {
Text("Le nombre de têtes de série ne devrait pas être inférieur au nombre de paires qualifiées sortantes").foregroundStyle(.red)
}
}
} }

Loading…
Cancel
Save