From 7c3725ce5bcd9b284cfca8c4cd1a1b5223704ba7 Mon Sep 17 00:00:00 2001 From: Raz Date: Wed, 16 Oct 2024 19:20:11 +0200 Subject: [PATCH] fix stuff --- PadelClub/Data/Match.swift | 18 ++- PadelClub/Data/TeamRegistration.swift | 8 ++ .../Calling/Components/MenuWarningView.swift | 2 +- PadelClub/Views/Cashier/CashierView.swift | 8 +- .../Components/GroupStageTeamView.swift | 2 +- .../Views/GroupStage/GroupStageView.swift | 19 ++- .../GroupStageTeamReplacementView.swift | 2 +- .../Match/Components/PlayerBlockView.swift | 20 ++-- .../Views/Round/LoserRoundSettingsView.swift | 21 ++-- PadelClub/Views/Round/RoundSettingsView.swift | 112 ++++++++++-------- .../Team/Components/TeamHeaderView.swift | 4 +- PadelClub/Views/Team/TeamRowView.swift | 8 +- .../Views/Tournament/FileImportView.swift | 7 +- .../Screen/TournamentRankView.swift | 4 +- 14 files changed, 133 insertions(+), 102 deletions(-) diff --git a/PadelClub/Data/Match.swift b/PadelClub/Data/Match.swift index 7c4eb85..2caee20 100644 --- a/PadelClub/Data/Match.swift +++ b/PadelClub/Data/Match.swift @@ -347,15 +347,21 @@ defer { guard let forwardMatch = _forwardMatch(inRound: roundObject) else { return } guard let next = _otherMatch() else { return } if next.disabled && byeState == false && next.byeState == false { - forwardMatch.byeState = false - forwardMatch._toggleMatchDisableState(state, forward: true) + if forwardMatch.disabled != state || forwardMatch.byeState { + forwardMatch.byeState = false + forwardMatch._toggleMatchDisableState(state, forward: true) + } } else if byeState && next.byeState { print("don't disable forward match") - forwardMatch.byeState = false - forwardMatch._toggleMatchDisableState(false, forward: true) + if forwardMatch.byeState || forwardMatch.disabled { + forwardMatch.byeState = false + forwardMatch._toggleMatchDisableState(false, forward: true) + } } else { - forwardMatch.byeState = true - forwardMatch._toggleMatchDisableState(state, forward: true) + if forwardMatch.byeState == false || forwardMatch.disabled != state { + forwardMatch.byeState = true + forwardMatch._toggleMatchDisableState(state, forward: true) + } } // if next.disabled == false { diff --git a/PadelClub/Data/TeamRegistration.swift b/PadelClub/Data/TeamRegistration.swift index b85fceb..1b46a68 100644 --- a/PadelClub/Data/TeamRegistration.swift +++ b/PadelClub/Data/TeamRegistration.swift @@ -536,6 +536,14 @@ final class TeamRegistration: ModelObject, Storable { matches().sorted(by: \.computedEndDateForSorting).last?.endDate } + func teamNameLabel() -> String { + if let name, name.isEmpty == false { + return name + } else { + return "Toute l'équipe" + } + } + enum CodingKeys: String, CodingKey { case _id = "id" case _tournament = "tournament" diff --git a/PadelClub/Views/Calling/Components/MenuWarningView.swift b/PadelClub/Views/Calling/Components/MenuWarningView.swift index ef094a0..d770ab1 100644 --- a/PadelClub/Views/Calling/Components/MenuWarningView.swift +++ b/PadelClub/Views/Calling/Components/MenuWarningView.swift @@ -124,7 +124,7 @@ struct MenuWarningView: View { @ViewBuilder func _teamActionView(_ team: TeamRegistration) -> some View { - Menu(team.name ?? "Toute l'équipe") { + Menu(team.teamNameLabel()) { let players = team.players() _actionView(players: players) } diff --git a/PadelClub/Views/Cashier/CashierView.swift b/PadelClub/Views/Cashier/CashierView.swift index b022259..34cf916 100644 --- a/PadelClub/Views/Cashier/CashierView.swift +++ b/PadelClub/Views/Cashier/CashierView.swift @@ -377,8 +377,8 @@ struct CashierView: View { } } header: { HStack { - if let name = team.name { - Text(name) + if let teamName = team.name, teamName.isEmpty == false { + Text(teamName) } if displayTournamentTitle, let tournamentTitle = team.tournamentObject()?.tournamentTitle() { Spacer() @@ -418,8 +418,8 @@ struct CashierView: View { EditablePlayerView(player: player, editingOptions: editingOptions) } } header: { - if let name = team.name { - Text(name) + if let teamName = team.name, teamName.isEmpty == false { + Text(teamName) } if displayTournamentTitle, let tournamentTitle = team.tournamentObject()?.tournamentTitle() { diff --git a/PadelClub/Views/GroupStage/Components/GroupStageTeamView.swift b/PadelClub/Views/GroupStage/Components/GroupStageTeamView.swift index 1d4b467..d839870 100644 --- a/PadelClub/Views/GroupStage/Components/GroupStageTeamView.swift +++ b/PadelClub/Views/GroupStage/Components/GroupStageTeamView.swift @@ -48,7 +48,7 @@ struct GroupStageTeamView: View { var body: some View { List { Section { - if let name = team.name { + if let name = team.name, name.isEmpty == false { Text(name).foregroundStyle(.secondary) } ForEach(team.players()) { player in diff --git a/PadelClub/Views/GroupStage/GroupStageView.swift b/PadelClub/Views/GroupStage/GroupStageView.swift index 292347b..63abc49 100644 --- a/PadelClub/Views/GroupStage/GroupStageView.swift +++ b/PadelClub/Views/GroupStage/GroupStageView.swift @@ -142,17 +142,16 @@ struct GroupStageView: View { .font(.footnote) HStack { VStack(alignment: .leading) { - if let teamName = team.name { - Text(teamName).font(.title3) - } else { - ForEach(team.players()) { player in - Text(player.playerLabel()).lineLimit(1) - .overlay { - if player.hasArrived && team.isHere() == false { - Color.green.opacity(0.6) - } + if let teamName = team.name, teamName.isEmpty == false { + Text(teamName).foregroundStyle(.secondary).font(.footnote) + } + ForEach(team.players()) { player in + Text(player.playerLabel()).lineLimit(1) + .overlay { + if player.hasArrived && team.isHere() == false { + Color.green.opacity(0.6) } - } + } } } Spacer() diff --git a/PadelClub/Views/GroupStage/Shared/GroupStageTeamReplacementView.swift b/PadelClub/Views/GroupStage/Shared/GroupStageTeamReplacementView.swift index cf613a4..dbc5673 100644 --- a/PadelClub/Views/GroupStage/Shared/GroupStageTeamReplacementView.swift +++ b/PadelClub/Views/GroupStage/Shared/GroupStageTeamReplacementView.swift @@ -54,7 +54,7 @@ struct GroupStageTeamReplacementView: View { Section { Picker(selection: $selectedPlayer) { HStack { - Text(team.name ?? "Toute l'équipe") + Text(team.teamNameLabel()) Spacer() Text(team.weight.formatted()).bold() } diff --git a/PadelClub/Views/Match/Components/PlayerBlockView.swift b/PadelClub/Views/Match/Components/PlayerBlockView.swift index 864a734..11c7ee8 100644 --- a/PadelClub/Views/Match/Components/PlayerBlockView.swift +++ b/PadelClub/Views/Match/Components/PlayerBlockView.swift @@ -58,22 +58,20 @@ struct PlayerBlockView: View { Text("Repêchée").italic().font(.caption) } - if let name = team?.name { - Text(name).font(.title3) - } else { - ForEach(names, id: \.self) { name in - Text(name).lineLimit(1) - } + if let teamName = team?.name { + Text(teamName).foregroundStyle(.secondary).font(.footnote) + } + ForEach(names, id: \.self) { name in + Text(name).lineLimit(1) } } else { ZStack(alignment: .leading) { VStack { - if let name = team?.name { - Text(name).font(.title3) - } else { - Text("longLabelPlayerOne").lineLimit(1) - Text("longLabelPlayerTwo").lineLimit(1) + if let teamName = team?.name { + Text(teamName).foregroundStyle(.secondary).font(.footnote) } + Text("longLabelPlayerOne").lineLimit(1) + Text("longLabelPlayerTwo").lineLimit(1) } .opacity(0) Text(_defaultLabel()).foregroundStyle(.secondary).lineLimit(1) diff --git a/PadelClub/Views/Round/LoserRoundSettingsView.swift b/PadelClub/Views/Round/LoserRoundSettingsView.swift index eb0c827..f39455f 100644 --- a/PadelClub/Views/Round/LoserRoundSettingsView.swift +++ b/PadelClub/Views/Round/LoserRoundSettingsView.swift @@ -80,15 +80,7 @@ struct LoserRoundSettingsView: View { Section { RowButtonView("Créer les matchs de classements", role: .destructive) { - upperBracketRound.round.buildLoserBracket() - upperBracketRound.round.disabledMatches().forEach { match in - match._toggleLoserMatchDisableState(true) - } - do { - try self.tournament.tournamentStore.matches.addOrUpdate(contentOfs: upperBracketRound.round.allLoserRoundMatches()) - } catch { - Logger.error(error) - } + await _addLoserBracketMatches() } } .disabled(upperBracketRound.round.loserRounds().isEmpty == false) @@ -147,6 +139,17 @@ struct LoserRoundSettingsView: View { Text(" Modifier quand même ?").foregroundStyle(.red) } + private func _addLoserBracketMatches() async { + upperBracketRound.round.buildLoserBracket() + upperBracketRound.round.disabledMatches().forEach { match in + match._toggleLoserMatchDisableState(true) + } + do { + try self.tournament.tournamentStore.matches.addOrUpdate(contentOfs: upperBracketRound.round.allLoserRoundMatches()) + } catch { + Logger.error(error) + } + } } //#Preview { diff --git a/PadelClub/Views/Round/RoundSettingsView.swift b/PadelClub/Views/Round/RoundSettingsView.swift index 53a16ab..3dcd33e 100644 --- a/PadelClub/Views/Round/RoundSettingsView.swift +++ b/PadelClub/Views/Round/RoundSettingsView.swift @@ -93,64 +93,14 @@ struct RoundSettingsView: View { Section { let roundIndex = tournament.rounds().count RowButtonView("Ajouter " + RoundRule.roundName(fromRoundIndex: roundIndex), role: .destructive) { - let round = Round(tournament: tournament.id, index: roundIndex, matchFormat: tournament.matchFormat) - let matchCount = RoundRule.numberOfMatches(forRoundIndex: roundIndex) - let matchStartIndex = RoundRule.matchIndex(fromRoundIndex: roundIndex) - let nextRound = round.nextRound() - var currentIndex = 0 - let matches = (0.. = Set() @State private var chunkByParameter: Bool = true + enum ChunkMode { + case byParameter + case byCoupleOfLines + } + init(defaultFileProvider: FileImportManager.FileProvider = .frenchFederation) { _fileProvider = .init(wrappedValue: defaultFileProvider) } @@ -558,7 +563,7 @@ struct FileImportView: View { Section { HStack { VStack(alignment: .leading) { - if let teamName = team.name { + if let teamName = team.name, teamName.isEmpty == false { Text(teamName).foregroundStyle(.secondary) } ForEach(team.players.sorted(by: \.computedRank)) { diff --git a/PadelClub/Views/Tournament/Screen/TournamentRankView.swift b/PadelClub/Views/Tournament/Screen/TournamentRankView.swift index ba33832..f53425f 100644 --- a/PadelClub/Views/Tournament/Screen/TournamentRankView.swift +++ b/PadelClub/Views/Tournament/Screen/TournamentRankView.swift @@ -233,8 +233,8 @@ struct TournamentRankView: View { Divider() VStack(alignment: .leading) { - if let name = team.name { - Text(name).foregroundStyle(.secondary) + if let teamName = team.name, teamName.isEmpty == false { + Text(teamName).foregroundStyle(.secondary) } ForEach(team.players()) { player in