From 6b02462b326dd6f7d1997bc8e51b64d4401c95f4 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Wed, 10 Jul 2024 05:41:12 +0200 Subject: [PATCH] wip test --- PadelClub/Views/Components/MatchListView.swift | 2 +- .../Views/Match/Components/MatchDateView.swift | 7 +------ PadelClub/Views/Match/EditSharingView.swift | 5 +++-- PadelClub/Views/Match/MatchDetailView.swift | 15 ++++++++------- PadelClub/Views/Match/MatchRowView.swift | 3 --- PadelClub/Views/Match/MatchSetupView.swift | 3 +-- .../Views/Navigation/Ongoing/OngoingView.swift | 3 +-- PadelClub/Views/Planning/PlanningView.swift | 1 - PadelClub/Views/Round/LoserRoundView.swift | 2 +- PadelClub/Views/Round/RoundView.swift | 2 +- PadelClub/Views/Score/EditScoreView.swift | 9 ++------- 11 files changed, 19 insertions(+), 33 deletions(-) diff --git a/PadelClub/Views/Components/MatchListView.swift b/PadelClub/Views/Components/MatchListView.swift index 464248d..412ee38 100644 --- a/PadelClub/Views/Components/MatchListView.swift +++ b/PadelClub/Views/Components/MatchListView.swift @@ -34,7 +34,7 @@ struct MatchListView: View { DisclosureGroup(isExpanded: $isExpanded) { if let matches { ForEach(matches) { match in - MatchRowView(match: match, tournament: self.tournament, matchViewStyle: matchViewStyle) + MatchRowView(match: match, matchViewStyle: matchViewStyle) .listRowInsets(EdgeInsets(top: 0, leading: -2, bottom: 0, trailing: 8)) } } diff --git a/PadelClub/Views/Match/Components/MatchDateView.swift b/PadelClub/Views/Match/Components/MatchDateView.swift index 4185cff..e208067 100644 --- a/PadelClub/Views/Match/Components/MatchDateView.swift +++ b/PadelClub/Views/Match/Components/MatchDateView.swift @@ -11,7 +11,6 @@ import LeStorage struct MatchDateView: View { @EnvironmentObject var dataStore: DataStore - @Environment(Tournament.self) var tournament: Tournament var match: Match var showPrefix: Bool = false @@ -19,10 +18,6 @@ struct MatchDateView: View { private var hasWalkoutTeam: Bool private var hasEnded: Bool - var tournamentStore: TournamentStore { - return self.tournament.tournamentStore - } - init(match: Match, showPrefix: Bool) { self.match = match self.showPrefix = showPrefix @@ -150,7 +145,7 @@ struct MatchDateView: View { private func _save() { do { - try self.tournamentStore.matches.addOrUpdate(instance: match) + try self.match.tournamentStore.matches.addOrUpdate(instance: match) } catch { Logger.error(error) } diff --git a/PadelClub/Views/Match/EditSharingView.swift b/PadelClub/Views/Match/EditSharingView.swift index de5a331..ff82dc3 100644 --- a/PadelClub/Views/Match/EditSharingView.swift +++ b/PadelClub/Views/Match/EditSharingView.swift @@ -10,7 +10,6 @@ import TipKit import CoreTransferable struct EditSharingView: View { - @Environment(Tournament.self) var tournament: Tournament var match: Match @State private var displayRank: Bool = false @State private var displayTeamTitle: Bool = false @@ -38,7 +37,9 @@ struct EditSharingView: View { messageData.append(locAndTime) } - messageData.append(tournament.tournamentTitle()) + if let tournament = match.currentTournament() { + messageData.append(tournament.tournamentTitle()) + } let message = [match.isLoserBracket ? "Classement" : nil, match.roundTitle(), match.isLoserBracket ? nil : ((match.index > 0 || match.isGroupStage()) ? match.matchTitle(.short) : nil)].compactMap({ $0 }).joined(separator: " ") diff --git a/PadelClub/Views/Match/MatchDetailView.swift b/PadelClub/Views/Match/MatchDetailView.swift index a9c7ce5..8207b58 100644 --- a/PadelClub/Views/Match/MatchDetailView.swift +++ b/PadelClub/Views/Match/MatchDetailView.swift @@ -11,7 +11,6 @@ import LeStorage struct MatchDetailView: View { @EnvironmentObject var dataStore: DataStore - @Environment(Tournament.self) var tournament: Tournament @EnvironmentObject var networkMonitor: NetworkMonitor @Environment(\.dismiss) var dismiss @@ -36,7 +35,7 @@ struct MatchDetailView: View { @State var showUserCreationView: Bool = false var tournamentStore: TournamentStore { - return self.tournament.tournamentStore + return match.tournamentStore } var messageSentFailed: Binding { @@ -94,8 +93,10 @@ struct MatchDetailView: View { showDetails = true } Spacer() - MenuWarningView(tournament: self.match.currentTournament()!, teams: match.teams(), message: match.matchWarningMessage(), umpireMail: dataStore.user.email, subject: match.matchWarningSubject(), contactType: $contactType) - .buttonStyle(.borderless) + if let tournament = match.currentTournament() { + MenuWarningView(tournament: tournament, teams: match.teams(), message: match.matchWarningMessage(), umpireMail: dataStore.user.email, subject: match.matchWarningSubject(), contactType: $contactType) + .buttonStyle(.borderless) + } } } } @@ -455,7 +456,7 @@ struct MatchDetailView: View { if match.isReady() == false && match.teams().count == 2 { let teamsScores = match.getOrCreateTeamScores() do { - try self.tournamentStore.teamScores.addOrUpdate(contentOfs: teamsScores) + try tournamentStore.teamScores.addOrUpdate(contentOfs: teamsScores) } catch { Logger.error(error) } @@ -477,7 +478,7 @@ struct MatchDetailView: View { } fileprivate func _payTournamentAndExecute(_ handler: () -> ()) { - guard let tournament = self.match.currentTournament() else { fatalError("missing tournament") } + guard let tournament = match.currentTournament() else { fatalError("missing tournament") } do { try tournament.payIfNecessary() @@ -489,7 +490,7 @@ struct MatchDetailView: View { private func save() { do { - try self.tournamentStore.matches.addOrUpdate(instance: match) + try tournamentStore.matches.addOrUpdate(instance: match) } catch { Logger.error(error) } diff --git a/PadelClub/Views/Match/MatchRowView.swift b/PadelClub/Views/Match/MatchRowView.swift index 9b17dc1..3c486a8 100644 --- a/PadelClub/Views/Match/MatchRowView.swift +++ b/PadelClub/Views/Match/MatchRowView.swift @@ -10,7 +10,6 @@ import SwiftUI struct MatchRowView: View { var match: Match - var tournament: Tournament let matchViewStyle: MatchViewStyle var title: String? = nil @@ -59,13 +58,11 @@ struct MatchRowView: View { NavigationLink { MatchDetailView(match: match, matchViewStyle: matchViewStyle) - .environment(self.tournament) } label: { MatchSummaryView(match: match, matchViewStyle: matchViewStyle, title: title) .contextMenu { NavigationLink { EditSharingView(match: match) - .environment(self.tournament) } label: { Text("Partage sur les réseaux sociaux") } diff --git a/PadelClub/Views/Match/MatchSetupView.swift b/PadelClub/Views/Match/MatchSetupView.swift index 52e1418..8a6a5d0 100644 --- a/PadelClub/Views/Match/MatchSetupView.swift +++ b/PadelClub/Views/Match/MatchSetupView.swift @@ -11,13 +11,12 @@ import LeStorage struct MatchSetupView: View { @EnvironmentObject var dataStore: DataStore - @Environment(Tournament.self) var tournament: Tournament var match: Match @State private var seedGroup: SeedInterval? var tournamentStore: TournamentStore { - return self.tournament.tournamentStore + return match.tournamentStore } @ViewBuilder diff --git a/PadelClub/Views/Navigation/Ongoing/OngoingView.swift b/PadelClub/Views/Navigation/Ongoing/OngoingView.swift index b8107a7..736a97f 100644 --- a/PadelClub/Views/Navigation/Ongoing/OngoingView.swift +++ b/PadelClub/Views/Navigation/Ongoing/OngoingView.swift @@ -32,8 +32,7 @@ struct OngoingView: View { if let tournament = match.currentTournament() { Section { - MatchRowView(match: match, tournament: tournament, matchViewStyle: .standardStyle) - .environment(tournament) + MatchRowView(match: match, matchViewStyle: .standardStyle) } header: { HStack { Text(tournament.tournamentTitle(.short)) diff --git a/PadelClub/Views/Planning/PlanningView.swift b/PadelClub/Views/Planning/PlanningView.swift index ac413ff..a4780a4 100644 --- a/PadelClub/Views/Planning/PlanningView.swift +++ b/PadelClub/Views/Planning/PlanningView.swift @@ -37,7 +37,6 @@ struct PlanningView: View { ForEach(_matches) { match in NavigationLink { MatchDetailView(match: match, matchViewStyle: .sectionedStandardStyle) - .environment(self.tournament) } label: { LabeledContent { if let courtName = match.courtName() { diff --git a/PadelClub/Views/Round/LoserRoundView.swift b/PadelClub/Views/Round/LoserRoundView.swift index 5a0f4c1..d36bb31 100644 --- a/PadelClub/Views/Round/LoserRoundView.swift +++ b/PadelClub/Views/Round/LoserRoundView.swift @@ -40,7 +40,7 @@ struct LoserRoundView: View { if matches.isEmpty == false { Section { ForEach(matches) { match in - MatchRowView(match: match, tournament: self.tournament, matchViewStyle: .sectionedStandardStyle) + MatchRowView(match: match, matchViewStyle: .sectionedStandardStyle) .overlay { if match.disabled && isEditingTournamentSeed.wrappedValue == true { Image(systemName: "xmark") diff --git a/PadelClub/Views/Round/RoundView.swift b/PadelClub/Views/Round/RoundView.swift index ec15fe4..fe80468 100644 --- a/PadelClub/Views/Round/RoundView.swift +++ b/PadelClub/Views/Round/RoundView.swift @@ -254,7 +254,7 @@ struct RoundView: View { ForEach(displayableMatches) { match in let matchTitle = match.matchTitle(.short, inMatches: displayableMatches) Section { - MatchRowView(match: match, tournament: self.tournament, matchViewStyle: .sectionedStandardStyle, title: matchTitle) + MatchRowView(match: match, matchViewStyle: .sectionedStandardStyle, title: matchTitle) } header: { HStack { Text(upperRound.round.roundTitle(.wide)) diff --git a/PadelClub/Views/Score/EditScoreView.swift b/PadelClub/Views/Score/EditScoreView.swift index 0e681d9..c1de469 100644 --- a/PadelClub/Views/Score/EditScoreView.swift +++ b/PadelClub/Views/Score/EditScoreView.swift @@ -14,12 +14,7 @@ struct EditScoreView: View { @ObservedObject var matchDescriptor: MatchDescriptor @Environment(\.dismiss) private var dismiss - @Environment(Tournament.self) var tournament: Tournament - - var tournamentStore: TournamentStore { - return self.tournament.tournamentStore - } - + func walkout(_ team: TeamPosition) { self.matchDescriptor.match?.setWalkOut(team) save() @@ -111,7 +106,7 @@ struct EditScoreView: View { func save() { if let match = matchDescriptor.match { do { - try self.tournamentStore.matches.addOrUpdate(instance: match) + try match.tournamentStore.matches.addOrUpdate(instance: match) } catch { Logger.error(error) }