add losing group stage position selection consolante

sync3
Raz 6 months ago
parent 1e41f51712
commit ccf6b05e0d
  1. 8
      PadelClub/Data/Tournament.swift
  2. 56
      PadelClub/Views/Tournament/ConsolationTournamentImportView.swift

@ -2485,6 +2485,14 @@ defer {
}
}
func groupStageLosingPositions() -> [Int] {
guard let maxSize = groupStages().map({ $0.size }).max() else {
return []
}
let leftInterval = qualifiedPerGroupStage + 1
return Array(leftInterval...maxSize)
}
// MARK: - Payments & Crypto

@ -16,6 +16,7 @@ struct ConsolationTournamentImportView: View {
@State private var selectedTournament: Tournament?
@State private var selectedImportSelector: ImportSelector = .groupStage
@State private var selectedImportType: ImportType = .losers
@State private var selectedGroupStagePosition: Set<Int> = Set()
enum ImportType: Int, Identifiable, CaseIterable {
case losers
@ -134,6 +135,36 @@ struct ConsolationTournamentImportView: View {
Text("Type")
}
}
if selectedImportSelector == .groupStage, selectedImportType == .losers {
NavigationLink {
List(selection: $selectedGroupStagePosition) {
ForEach(selectedTournament.groupStageLosingPositions()) { position in
let text: String = "\(position)" + position.ordinalFormattedSuffix()
Text(text)
.tag(position)
}
}
.environment(\.editMode, Binding.constant(EditMode.active))
.navigationTitle("Position des poules")
.navigationBarTitleDisplayMode(.inline)
.toolbarBackground(.visible, for: .navigationBar)
} label: {
LabeledContent {
if selectedGroupStagePosition.isEmpty {
Text("Tous les perdants")
} else {
let value: String = selectedGroupStagePosition.map({ position in
let text: String = "\(position)" + position.ordinalFormattedSuffix()
return text
}).joined(separator: ", ")
Text(value)
}
} label: {
Text("Sélection des positions")
}
}
}
}
}
@ -154,16 +185,15 @@ struct ConsolationTournamentImportView: View {
let teams = _teamsToImport(selectedTournament: selectedTournament)
Section {
RowButtonView("Importer les équipes") {
await _importTeams(selectedTournament: selectedTournament, teams: teams)
dismiss()
}
.disabled(teams.isEmpty)
} footer: {
if teams.isEmpty {
Text("Aucune équipe détectée").foregroundStyle(.logoRed)
if teams.isEmpty == false {
Section {
RowButtonView("Importer les \(teams.count) équipes") {
await _importTeams(selectedTournament: selectedTournament, teams: teams)
dismiss()
}
}
} else {
Text("Aucune équipe à importer").foregroundStyle(.logoRed)
}
}
}
@ -185,7 +215,13 @@ struct ConsolationTournamentImportView: View {
teams = selectedTournament.groupStageTeams().filter({
switch selectedImportType {
case .losers:
return $0.qualified == false
if selectedGroupStagePosition.isEmpty {
return $0.qualified == false
} else if let position = $0.groupStagePosition {
return $0.qualified == false && selectedGroupStagePosition.contains(position)
} else {
return $0.qualified == false
}
case .winners:
return $0.qualified
case .all:

Loading…
Cancel
Save