From 51395b60a4fed6a32cdcf46b9e43da9095a0dba1 Mon Sep 17 00:00:00 2001 From: Raz Date: Wed, 19 Mar 2025 10:41:41 +0100 Subject: [PATCH] fix wc stuff display --- PadelClub.xcodeproj/project.pbxproj | 4 +- PadelClub/Data/TeamRegistration.swift | 56 ++++++++++++++----- .../Views/GroupStage/GroupStageView.swift | 14 ++++- .../Match/Components/PlayerBlockView.swift | 51 ++++++++++------- PadelClub/Views/Team/TeamPickerView.swift | 12 +--- PadelClub/Views/Team/TeamRowView.swift | 27 ++++----- .../Screen/TableStructureView.swift | 1 + 7 files changed, 99 insertions(+), 66 deletions(-) diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index 2e1b674..d2c05a1 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -3344,7 +3344,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.1.23; + MARKETING_VERSION = 1.1.24; PRODUCT_BUNDLE_IDENTIFIER = app.padelclub; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; @@ -3389,7 +3389,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - MARKETING_VERSION = 1.1.23; + MARKETING_VERSION = 1.1.24; PRODUCT_BUNDLE_IDENTIFIER = app.padelclub; PRODUCT_NAME = "$(TARGET_NAME)"; PROVISIONING_PROFILE_SPECIFIER = ""; diff --git a/PadelClub/Data/TeamRegistration.swift b/PadelClub/Data/TeamRegistration.swift index 72de9bc..7019524 100644 --- a/PadelClub/Data/TeamRegistration.swift +++ b/PadelClub/Data/TeamRegistration.swift @@ -600,7 +600,7 @@ final class TeamRegistration: ModelObject, Storable { func wildcardLabel() -> String? { if isWildCard() { - let wildcardLabel: String = ["wildcard", (wildCardBracket ? "tableau" : "poule")].joined(separator: " ") + let wildcardLabel: String = ["Wildcard", (wildCardBracket ? "Tableau" : "Poule")].joined(separator: " ") return wildcardLabel } else { return nil @@ -647,22 +647,48 @@ final class TeamRegistration: ModelObject, Storable { unsortedPlayers().count > 0 } - func bracketMatchTitleAndQualifiedStatus() -> String? { - let v = groupStageObject()?.groupStageTitle() - var base = "Qualifié" - if qualified { - if let groupStageTitle = groupStageObject()?.groupStageTitle() { - base = base + " (\(groupStageTitle))" - } + func teamInitialPositionBracket() -> String? { + let round = initialMatch()?.roundAndMatchTitle() + if let round { + return round } - - let suffix = qualified ? nil : groupStageObject()?.groupStageTitle() - let initalMatchTitle = initialMatch()?.roundAndMatchTitle() ?? suffix - let values = [qualified ? base : nil, initalMatchTitle].compactMap({ $0 }) - if values.isEmpty { - return nil + return nil + } + + func teamInitialPositionGroupStage() -> String? { + let groupStage = self.groupStageObject() + let group = groupStage?.groupStageTitle(.title) + var groupPositionLabel: String? = nil + if let finalPosition = groupStage?.finalPosition(ofTeam: self) { + groupPositionLabel = (finalPosition + 1).ordinalFormatted() + } else if let groupStagePosition { + groupPositionLabel = "\(groupStagePosition + 1)" + } + + if let group { + if let groupPositionLabel { + return [group, "#\(groupPositionLabel)"].joined(separator: " ") + } else { + return group + } + } + return nil + } + + func qualifiedStatus(hideBracketStatus: Bool = false) -> String? { + let teamInitialPositionBracket = teamInitialPositionBracket() + let groupStageTitle = teamInitialPositionGroupStage() + + let base: String? = qualified ? "Qualifié" : nil + if let groupStageTitle, let teamInitialPositionBracket, hideBracketStatus == false { + return [base, groupStageTitle, ">", teamInitialPositionBracket].compactMap({ $0 }).joined(separator: " ") + } else if let groupStageTitle { + return [base, groupStageTitle].compactMap({ $0 }).joined(separator: " ") + } else if hideBracketStatus == false { + return teamInitialPositionBracket } - return values.joined(separator: " -> ") + + return nil } enum CodingKeys: String, CodingKey { diff --git a/PadelClub/Views/GroupStage/GroupStageView.swift b/PadelClub/Views/GroupStage/GroupStageView.swift index 9fc489f..adbb27f 100644 --- a/PadelClub/Views/GroupStage/GroupStageView.swift +++ b/PadelClub/Views/GroupStage/GroupStageView.swift @@ -140,12 +140,16 @@ struct GroupStageView: View { GroupStageTeamView(groupStage: groupStage, team: team) .environment(self.tournament) } label: { + let players = team.players() VStack(alignment: .leading, spacing: 4.0) { HStack(spacing: 6.0) { Text("#\(groupStagePosition + 1)") - if groupStage.tournamentObject()?.hideWeight() == false { + if players.isEmpty == false, groupStage.tournamentObject()?.hideWeight() == false { Text("Poids \(team.weight)") } + if players.isEmpty == false, team.isWildCard() { + Text("wildcard").foregroundStyle(.logoRed).font(.caption).italic() + } Spacer() if team.qualified { Text("qualifié") @@ -156,8 +160,14 @@ struct GroupStageView: View { VStack(alignment: .leading) { if let teamName = team.name, teamName.isEmpty == false { Text(teamName).foregroundStyle(.secondary).font(.footnote) + } else if players.isEmpty { + if team.isWildCard() { + Text("Place réservée wildcard") + } else { + Text("Place réservée") + } } - ForEach(team.players()) { player in + ForEach(players) { player in Text(player.playerLabel()).lineLimit(1) .overlay { if player.hasArrived && team.isHere() == false { diff --git a/PadelClub/Views/Match/Components/PlayerBlockView.swift b/PadelClub/Views/Match/Components/PlayerBlockView.swift index e2a7e15..5e9d2b3 100644 --- a/PadelClub/Views/Match/Components/PlayerBlockView.swift +++ b/PadelClub/Views/Match/Components/PlayerBlockView.swift @@ -74,39 +74,48 @@ struct PlayerBlockView: View { var body: some View { HStack { VStack(alignment: .leading) { - if let team { - if let teamScore, teamScore.luckyLoser != nil, match.isLoserBracket == false { - Text("Repêchée").italic().font(.caption) + ZStack(alignment: .leading) { + VStack { + if let teamName = team?.name { + Text(teamName).foregroundStyle(.secondary).font(.footnote) + } + Text("longLabelPlayerOne").lineLimit(1) + Text("longLabelPlayerTwo").lineLimit(1) } + .opacity(0) - if let teamName = team.name { - Text(teamName).foregroundStyle(.secondary).font(.footnote) - } - ForEach(team.players()) { player in - Text(player.playerLabel()).lineLimit(1) - .italic(player.isHere() == false) - .foregroundStyle(player.isHere() == false ? .secondary : .primary) - } - } else { - ZStack(alignment: .leading) { - VStack { - if let teamName = team?.name { - Text(teamName).foregroundStyle(.secondary).font(.footnote) + if let team { + if let teamScore, teamScore.luckyLoser != nil, match.isLoserBracket == false { + Text("Repêchée").italic().font(.caption) + } + + if let teamName = team.name { + Text(teamName).foregroundStyle(.secondary).font(.footnote) + } else if team.players().isEmpty { + if team.isWildCard() { + Text("Place réservée wildcard") + } else { + Text("Place réservée") } - Text("longLabelPlayerOne").lineLimit(1) - Text("longLabelPlayerTwo").lineLimit(1) } - .opacity(0) + VStack(alignment: .leading) { + ForEach(team.players()) { player in + Text(player.playerLabel()).lineLimit(1) + .italic(player.isHere() == false) + .foregroundStyle(player.isHere() == false ? .secondary : .primary) + } + } + } else { VStack(alignment: .leading) { ForEach(_defaultLabel(), id: \.self) { name in Text(name) - .foregroundStyle(.secondary) + .foregroundStyle(.secondary) .lineLimit(1) } } } } - + if displayRestingTime, let team { TeamRowView.TeamRestingView(team: team) } diff --git a/PadelClub/Views/Team/TeamPickerView.swift b/PadelClub/Views/Team/TeamPickerView.swift index 73b8d59..e8d3ad8 100644 --- a/PadelClub/Views/Team/TeamPickerView.swift +++ b/PadelClub/Views/Team/TeamPickerView.swift @@ -134,15 +134,9 @@ struct TeamPickerView: View { // presentTeamPickerView = false // } } label: { - VStack(alignment: .leading) { - if let roundAndMatchTitle = team.bracketMatchTitleAndQualifiedStatus() { - Text(roundAndMatchTitle) - .font(.headline) - .frame(maxWidth: .infinity, alignment: .leading) - } - TeamRowView(team: team) - } - .contentShape(Rectangle()) + TeamRowView(team: team) + .environment(\.isEditingTournamentSeed, .constant(false)) + .contentShape(Rectangle()) } .frame(maxWidth: .infinity) .buttonStyle(.plain) diff --git a/PadelClub/Views/Team/TeamRowView.swift b/PadelClub/Views/Team/TeamRowView.swift index bb32774..13b5ee0 100644 --- a/PadelClub/Views/Team/TeamRowView.swift +++ b/PadelClub/Views/Team/TeamRowView.swift @@ -9,7 +9,6 @@ import SwiftUI struct TeamRowView: View { @EnvironmentObject var dataStore: DataStore - @Environment(\.isEditingTournamentSeed) private var isEditingTournamentSeed var team: TeamRegistration var teamPosition: TeamPosition? = nil @@ -22,9 +21,7 @@ struct TeamRowView: View { TeamWeightView(team: team, teamPosition: teamPosition, teamIndex: teamIndex) } label: { VStack(alignment: .leading) { - if isEditingTournamentSeed.wrappedValue == false { - TeamHeadlineView(team: team) - } + TeamHeadlineView(team: team) TeamView(team: team) } if displayCallDate { @@ -78,23 +75,19 @@ struct TeamRowView: View { } struct TeamHeadlineView: View { + @Environment(\.isEditingTournamentSeed) private var isEditingTournamentSeed let team: TeamRegistration var body: some View { - HStack { - if let groupStage = team.groupStageObject() { - HStack { - Text(groupStage.groupStageTitle(.title)) - if let finalPosition = groupStage.finalPosition(ofTeam: team) { - Text((finalPosition + 1).ordinalFormatted()) - } - } - } else if let round = team.initialRound() { - Text(round.roundTitle(.wide)) - } - + VStack(alignment: .leading) { if let wildcardLabel = team.wildcardLabel() { - Text(wildcardLabel).italic().foregroundStyle(.red).font(.caption) + Text(wildcardLabel).italic().foregroundStyle(.logoRed).font(.caption) + } + + if let qualifiedStatus = team.qualifiedStatus(hideBracketStatus: isEditingTournamentSeed.wrappedValue == true) { + Text(qualifiedStatus) + .font(.caption) + .foregroundStyle(.secondary) } } } diff --git a/PadelClub/Views/Tournament/Screen/TableStructureView.swift b/PadelClub/Views/Tournament/Screen/TableStructureView.swift index 444ce72..9d8f20b 100644 --- a/PadelClub/Views/Tournament/Screen/TableStructureView.swift +++ b/PadelClub/Views/Tournament/Screen/TableStructureView.swift @@ -295,6 +295,7 @@ struct TableStructureView: View { RowButtonView("Remise-à-zéro", role: .destructive) { tournament.deleteGroupStages() tournament.deleteStructure() + structurePreset = PadelTournamentStructurePreset.manual } } }