From 4fe9743a32fee6a0fa1ce494e108273d31d2b120 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Tue, 30 Apr 2024 15:36:07 +0200 Subject: [PATCH] fix crash on add tournament groupstage score display fix score / weight toggle in groupstage --- PadelClub/Data/GroupStage.swift | 14 +++++--------- PadelClub/Views/Event/EventCreationView.swift | 1 - PadelClub/Views/GroupStage/GroupStageView.swift | 14 +++++++++++++- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/PadelClub/Data/GroupStage.swift b/PadelClub/Data/GroupStage.swift index b421f49..b1ac29f 100644 --- a/PadelClub/Data/GroupStage.swift +++ b/PadelClub/Data/GroupStage.swift @@ -94,18 +94,13 @@ class GroupStage: ModelObject, Storable { } } - func scoreLabel(forGroupStagePosition groupStagePosition: Int) -> String? { + func scoreLabel(forGroupStagePosition groupStagePosition: Int) -> (wins: String, losses: String, setsDifference: String?, gamesDifference: String?)? { if let scoreData = _score(forGroupStagePosition: groupStagePosition) { - let hideGameDifference = matchFormat.setsToWin == 1 + let hideSetDifference = matchFormat.setsToWin == 1 let setDifference = scoreData.setDifference.formatted(.number.sign(strategy: .always(includingZero: false))) let gameDifference = scoreData.gameDifference.formatted(.number.sign(strategy: .always(includingZero: false))) - var differenceAsString = "\n" + gameDifference + " jeux" - if hideGameDifference == false { - differenceAsString = "\n" + setDifference + " sets" + differenceAsString - } else { - differenceAsString = setDifference - } - return "\(scoreData.wins)/\(scoreData.loses) " + differenceAsString + return (wins: scoreData.wins.formatted(), losses: scoreData.loses.formatted(), setsDifference: hideSetDifference ? nil : setDifference, gamesDifference: gameDifference) +// return "\(scoreData.wins)/\(scoreData.loses) " + differenceAsString } else { return nil } @@ -114,6 +109,7 @@ class GroupStage: ModelObject, Storable { fileprivate func _score(forGroupStagePosition groupStagePosition: Int) -> TeamGroupStageScore? { guard let team = teamAt(groupStagePosition: groupStagePosition) else { return nil } let matches = matches(forGroupStagePosition: groupStagePosition).filter({ $0.hasEnded() }) + if matches.isEmpty { return nil } let wins = matches.filter { $0.winningTeamId == team.id }.count let loses = matches.filter { $0.losingTeamId == team.id }.count let differences = matches.compactMap { $0.scoreDifference(groupStagePosition) } diff --git a/PadelClub/Views/Event/EventCreationView.swift b/PadelClub/Views/Event/EventCreationView.swift index 2a07290..9bb2938 100644 --- a/PadelClub/Views/Event/EventCreationView.swift +++ b/PadelClub/Views/Event/EventCreationView.swift @@ -11,7 +11,6 @@ import TipKit struct EventCreationView: View { @Environment(\.dismiss) private var dismiss @EnvironmentObject var dataStore: DataStore - @Environment(FederalDataViewModel.self) private var federalDataViewModel: FederalDataViewModel @Environment(NavigationViewModel.self) private var navigation: NavigationViewModel @State private var eventType: EventType = .approvedTournament @State private var animationType: AnimationType = .upAndDown diff --git a/PadelClub/Views/GroupStage/GroupStageView.swift b/PadelClub/Views/GroupStage/GroupStageView.swift index 782fb36..2e6524f 100644 --- a/PadelClub/Views/GroupStage/GroupStageView.swift +++ b/PadelClub/Views/GroupStage/GroupStageView.swift @@ -115,7 +115,19 @@ struct GroupStageView: View { } Spacer() if let score = groupStage.scoreLabel(forGroupStagePosition: groupStagePosition) { - Text(score) + VStack(alignment: .center) { + HStack(spacing: 0.0) { + Text(score.wins) + Text("/") + Text(score.losses) + }.bold() + if let setsDifference = score.setsDifference { + Text(setsDifference + " sets") + } + if let gamesDifference = score.gamesDifference { + Text(gamesDifference + " jeux") + } + } } } }