fix wildcard pick issue

newoffer2025
Raz 6 months ago
parent faaff120d7
commit 579b4fdce2
  1. 2
      PadelClub/Views/GroupStage/GroupStageView.swift
  2. 2
      PadelClub/Views/Match/MatchSetupView.swift
  3. 22
      PadelClub/Views/Team/EditingTeamView.swift
  4. 36
      PadelClub/Views/Team/TeamPickerView.swift

@ -241,7 +241,7 @@ struct GroupStageView: View {
VStack(alignment: .leading, spacing: 0) {
Text("#\(index + 1)")
.font(.caption)
TeamPickerView(groupStagePosition: index, matchTypeContext: .groupStage, teamPicked: { team in
TeamPickerView(groupStagePosition: index, pickTypeContext: .groupStage, teamPicked: { team in
print(team.pasteData())
team.groupStage = groupStage.id
team.groupStagePosition = index

@ -64,7 +64,7 @@ struct MatchSetupView: View {
}
HStack {
let luckyLosers = walkOutSpot ? match.luckyLosers() : []
TeamPickerView(shouldConfirm: shouldConfirm, round: match.roundObject, matchTypeContext: matchTypeContext, luckyLosers: luckyLosers, teamPicked: { team in
TeamPickerView(shouldConfirm: shouldConfirm, round: match.roundObject, pickTypeContext: matchTypeContext == .bracket ? .bracket : .loserBracket, luckyLosers: luckyLosers, teamPicked: { team in
print(team.pasteData())
if walkOutSpot || team.bracketPosition != nil || matchTypeContext == .loserBracket {
match.setLuckyLoser(team: team, teamPosition: teamPosition)

@ -101,12 +101,22 @@ struct EditingTeamView: View {
HStack {
CopyPasteButtonView(pasteValue: team.playersPasteData())
Spacer()
NavigationLink {
GroupStageTeamReplacementView(team: team)
.environment(tournament)
} label: {
Text("Chercher à remplacer")
.underline()
if team.isWildCard(), team.unsortedPlayers().isEmpty {
TeamPickerView(pickTypeContext: .wildcard) { teamregistration in
teamregistration.wildCardBracket = team.wildCardBracket
teamregistration.wildCardGroupStage = team.wildCardGroupStage
tournament.tournamentStore?.teamRegistrations.addOrUpdate(instance: teamregistration)
tournament.tournamentStore?.teamRegistrations.delete(instance: team)
dismiss()
}
} else {
NavigationLink {
GroupStageTeamReplacementView(team: team)
.environment(tournament)
} label: {
Text("Chercher à remplacer")
.underline()
}
}
}
}

@ -8,6 +8,13 @@
import SwiftUI
import PadelClubData
public enum TeamPickType: String {
case bracket = "bracket"
case groupStage = "groupStage"
case loserBracket = "loserBracket"
case wildcard = "wildcard"
}
struct TeamPickerView: View {
@EnvironmentObject var dataStore: DataStore
@Environment(Tournament.self) var tournament: Tournament
@ -20,7 +27,7 @@ struct TeamPickerView: View {
var shouldConfirm: Bool = false
var groupStagePosition: Int? = nil
var round: Round? = nil
var matchTypeContext: MatchType = .bracket
var pickTypeContext: TeamPickType = .bracket
var luckyLosers: [TeamRegistration] = []
let teamPicked: ((TeamRegistration) -> (Void))
@ -31,21 +38,34 @@ struct TeamPickerView: View {
}
}
var wording: String {
switch pickTypeContext {
case .bracket:
return "Choisir"
case .groupStage:
return "Choisir"
case .loserBracket:
return "Choisir"
case .wildcard:
return "Choisir la wildcard"
}
}
var body: some View {
ConfirmButtonView(shouldConfirm: shouldConfirm, message: MatchSetupView.confirmationMessage) {
presentTeamPickerView = true
} label: {
Text("Choisir")
Text(wording)
.underline()
}
.sheet(isPresented: $presentTeamPickerView) {
NavigationStack {
List {
if matchTypeContext == .loserBracket, let losers = round?.parentRound?.losers() {
if pickTypeContext == .loserBracket, let losers = round?.parentRound?.losers() {
_sectionView(losers.sorted(by: \.weight, order: sortOrder), title: "Perdant du tour précédent")
}
if matchTypeContext == .loserBracket, let losers = round?.previousRound()?.winners() {
if pickTypeContext == .loserBracket, let losers = round?.previousRound()?.winners() {
_sectionView(losers.sorted(by: \.weight, order: sortOrder), title: "Gagnant du tour précédent")
}
@ -63,7 +83,11 @@ struct TeamPickerView: View {
let teams = tournament.selectedSortedTeams()
if matchTypeContext == .loserBracket {
if pickTypeContext == .wildcard {
_sectionView(tournament.waitingListSortedTeams(selectedSortedTeams: teams).sorted(by: \.weight, order: sortOrder), title: "Liste d'attente")
}
if pickTypeContext == .loserBracket {
_sectionView(teams.filter({ $0.inGroupStage() && $0.qualified == false }).sorted(by: \.weight, order: sortOrder), title: "Non qualifié de poules")
}
@ -145,7 +169,7 @@ struct TeamPickerView: View {
.frame(maxWidth: .infinity)
.buttonStyle(.plain)
.id(team.id)
.listRowView(isActive: matchTypeContext == .loserBracket && round?.teams().map({ $0.id }).contains(team.id) == true, color: .green, hideColorVariation: true)
.listRowView(isActive: pickTypeContext == .loserBracket && round?.teams().map({ $0.id }).contains(team.id) == true, color: .green, hideColorVariation: true)
// .confirmationDialog("Attention", isPresented: confirmationRequest, titleVisibility: .visible) {
// Button("Retirer du tableau", role: .destructive) {
// teamPicked(confirmTeam!)

Loading…
Cancel
Save