From 1843ab58d1c6097519fcfa2a857ac2bc3d5d0372 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Fri, 28 Feb 2025 11:02:03 +0100 Subject: [PATCH] fix team label and lucky loser stuff --- PadelClub/Data/Match.swift | 4 +++- PadelClub/Data/TeamRegistration.swift | 8 ++++++++ PadelClub/Views/Match/Components/MatchDateView.swift | 2 +- .../Views/Match/Components/PlayerBlockView.swift | 2 +- PadelClub/Views/Score/FollowUpMatchView.swift | 5 +++++ .../Views/Shared/SelectablePlayerListView.swift | 2 ++ PadelClub/Views/Team/TeamPickerView.swift | 12 ++++++++++-- PadelClub/Views/Team/TeamRowView.swift | 6 +++++- 8 files changed, 35 insertions(+), 6 deletions(-) diff --git a/PadelClub/Data/Match.swift b/PadelClub/Data/Match.swift index b80f645..5afa194 100644 --- a/PadelClub/Data/Match.swift +++ b/PadelClub/Data/Match.swift @@ -517,7 +517,7 @@ defer { return (groupStageObject.index + 1) * 100 + groupStageObject.indexOf(index) } guard let roundObject else { return index } - return roundObject.isLoserBracket() ? (roundObject.index + 1) * 10000 + indexInRound() : (roundObject.index + 1) * 1000 + indexInRound() + return (300 - (roundObject.theoryCumulativeMatchCount * 10 + roundObject.index * 22)) * 10 + indexInRound() } func previousMatches() -> [Match] { @@ -540,8 +540,10 @@ defer { func setWalkOut(_ teamPosition: TeamPosition) { let teamScoreWalkout = teamScore(teamPosition) ?? TeamScore(match: id, team: team(teamPosition)) teamScoreWalkout.walkOut = 0 + teamScoreWalkout.score = matchFormat.defaultWalkOutScore(true).compactMap({ String($0) }).joined(separator: ",") let teamScoreWinning = teamScore(teamPosition.otherTeam) ?? TeamScore(match: id, team: team(teamPosition.otherTeam)) teamScoreWinning.walkOut = nil + teamScoreWinning.score = matchFormat.defaultWalkOutScore(false).compactMap({ String($0) }).joined(separator: ",") do { try self.tournamentStore.teamScores.addOrUpdate(contentOfs: [teamScoreWalkout, teamScoreWinning]) } catch { diff --git a/PadelClub/Data/TeamRegistration.swift b/PadelClub/Data/TeamRegistration.swift index 6744812..8a9066e 100644 --- a/PadelClub/Data/TeamRegistration.swift +++ b/PadelClub/Data/TeamRegistration.swift @@ -645,6 +645,14 @@ final class TeamRegistration: ModelObject, Storable { func shouldDisplayRankAndWeight() -> Bool { unsortedPlayers().count > 0 } + + func bracketMatchTitleAndQualifiedStatus() -> String? { + let values = [qualified ? "Qualifié" : nil, initialMatch()?.roundAndMatchTitle()].compactMap({ $0 }) + if values.isEmpty { + return nil + } + return values.joined(separator: " -> ") + } enum CodingKeys: String, CodingKey { case _id = "id" diff --git a/PadelClub/Views/Match/Components/MatchDateView.swift b/PadelClub/Views/Match/Components/MatchDateView.swift index 51ccc19..5dd2187 100644 --- a/PadelClub/Views/Match/Components/MatchDateView.swift +++ b/PadelClub/Views/Match/Components/MatchDateView.swift @@ -30,7 +30,7 @@ struct MatchDateView: View { } var currentDate: Date { - Date().withoutSeconds() + Date() } var body: some View { diff --git a/PadelClub/Views/Match/Components/PlayerBlockView.swift b/PadelClub/Views/Match/Components/PlayerBlockView.swift index d4c8d73..e2a7e15 100644 --- a/PadelClub/Views/Match/Components/PlayerBlockView.swift +++ b/PadelClub/Views/Match/Components/PlayerBlockView.swift @@ -151,7 +151,7 @@ struct PlayerBlockView: View { } } } - } else if let team { + } else if let team, hasWon == false, isWalkOut == false { TeamWeightView(team: team, teamPosition: teamPosition) } } diff --git a/PadelClub/Views/Score/FollowUpMatchView.swift b/PadelClub/Views/Score/FollowUpMatchView.swift index 78cda7f..27a88a1 100644 --- a/PadelClub/Views/Score/FollowUpMatchView.swift +++ b/PadelClub/Views/Score/FollowUpMatchView.swift @@ -217,6 +217,11 @@ struct FollowUpMatchView: View { } #if DEBUG Spacer() + if let roundObject = match.roundObject { + Text(roundObject.index.formatted()) + Text(roundObject.theoryCumulativeMatchCount.formatted()) + } + Text(match.computedOrder.formatted()) FooterButtonView("copier l'id") { let pasteboard = UIPasteboard.general pasteboard.string = match.id diff --git a/PadelClub/Views/Shared/SelectablePlayerListView.swift b/PadelClub/Views/Shared/SelectablePlayerListView.swift index 4210ef9..16b7d7e 100644 --- a/PadelClub/Views/Shared/SelectablePlayerListView.swift +++ b/PadelClub/Views/Shared/SelectablePlayerListView.swift @@ -427,7 +427,9 @@ struct MySearchView: View { searchViewModel.selectedPlayers.insert(player) } label: { ImportedPlayerView(player: player, showFemaleInMaleAssimilation: searchViewModel.showFemaleInMaleAssimilation, showProgression: true) + .contentShape(Rectangle()) } + .frame(maxWidth: .infinity) .buttonStyle(.plain) } } header: { diff --git a/PadelClub/Views/Team/TeamPickerView.swift b/PadelClub/Views/Team/TeamPickerView.swift index 0515283..73b8d59 100644 --- a/PadelClub/Views/Team/TeamPickerView.swift +++ b/PadelClub/Views/Team/TeamPickerView.swift @@ -134,11 +134,19 @@ struct TeamPickerView: View { // presentTeamPickerView = false // } } label: { - TeamRowView(team: team) - .contentShape(Rectangle()) + VStack(alignment: .leading) { + if let roundAndMatchTitle = team.bracketMatchTitleAndQualifiedStatus() { + Text(roundAndMatchTitle) + .font(.headline) + .frame(maxWidth: .infinity, alignment: .leading) + } + TeamRowView(team: team) + } + .contentShape(Rectangle()) } .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) // .confirmationDialog("Attention", isPresented: confirmationRequest, titleVisibility: .visible) { // Button("Retirer du tableau", role: .destructive) { diff --git a/PadelClub/Views/Team/TeamRowView.swift b/PadelClub/Views/Team/TeamRowView.swift index 4a1ba04..bb32774 100644 --- a/PadelClub/Views/Team/TeamRowView.swift +++ b/PadelClub/Views/Team/TeamRowView.swift @@ -9,6 +9,8 @@ import SwiftUI struct TeamRowView: View { @EnvironmentObject var dataStore: DataStore + @Environment(\.isEditingTournamentSeed) private var isEditingTournamentSeed + var team: TeamRegistration var teamPosition: TeamPosition? = nil var displayCallDate: Bool = false @@ -20,7 +22,9 @@ struct TeamRowView: View { TeamWeightView(team: team, teamPosition: teamPosition, teamIndex: teamIndex) } label: { VStack(alignment: .leading) { - TeamHeadlineView(team: team) + if isEditingTournamentSeed.wrappedValue == false { + TeamHeadlineView(team: team) + } TeamView(team: team) } if displayCallDate {