From e85299973903cdec6094257987d9d44e8fdf2884 Mon Sep 17 00:00:00 2001 From: Raz Date: Mon, 18 Nov 2024 07:46:07 +0100 Subject: [PATCH] clean matchviewstyle to make it environment variable fix lag due to court used calculation on each match cell --- PadelClub.xcodeproj/project.pbxproj | 8 +++ PadelClub/Data/Match.swift | 15 ++--- PadelClub/Data/PlayerRegistration.swift | 4 ++ PadelClub/Utils/DisplayContext.swift | 26 -------- PadelClub/ViewModel/MatchViewStyle.swift | 51 ++++++++++++++++ .../Views/Components/MatchListView.swift | 4 +- .../Views/GroupStage/GroupStagesView.swift | 10 +-- .../LoserBracketFromGroupStageView.swift | 3 +- .../Match/Components/MatchDateView.swift | 8 +-- .../Match/Components/PlayerBlockView.swift | 23 ++++--- PadelClub/Views/Match/MatchDetailView.swift | 10 +-- PadelClub/Views/Match/MatchRowView.swift | 6 +- PadelClub/Views/Match/MatchSummaryView.swift | 61 +++++++++++-------- .../Navigation/Ongoing/OngoingView.swift | 3 +- .../Views/Planning/PlanningByCourtView.swift | 3 +- PadelClub/Views/Planning/PlanningView.swift | 4 +- PadelClub/Views/Round/LoserRoundView.swift | 3 +- PadelClub/Views/Round/RoundView.swift | 3 +- PadelClub/Views/Score/FollowUpMatchView.swift | 3 +- PadelClub/Views/Team/TeamRestingView.swift | 3 +- 20 files changed, 151 insertions(+), 100 deletions(-) create mode 100644 PadelClub/ViewModel/MatchViewStyle.swift diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index 57ea77b..a6803c2 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -789,6 +789,9 @@ FFB9C8712BBADDE200A0EF4F /* Selectable.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFB9C8702BBADDE200A0EF4F /* Selectable.swift */; }; FFB9C8752BBADDF700A0EF4F /* SeedInterval.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFB9C8742BBADDF700A0EF4F /* SeedInterval.swift */; }; FFBA2D2D2CA2CE9E00D5BBDD /* CodingContainer+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C4C33F752C9B1EC5006316DE /* CodingContainer+Extensions.swift */; }; + FFBE62052CE9DA0900815D33 /* MatchViewStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFBE62042CE9DA0900815D33 /* MatchViewStyle.swift */; }; + FFBE62062CE9DA0900815D33 /* MatchViewStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFBE62042CE9DA0900815D33 /* MatchViewStyle.swift */; }; + FFBE62072CE9DA0900815D33 /* MatchViewStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFBE62042CE9DA0900815D33 /* MatchViewStyle.swift */; }; FFBF065C2BBD2657009D6715 /* GroupStageTeamView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFBF065B2BBD2657009D6715 /* GroupStageTeamView.swift */; }; FFBF065E2BBD8040009D6715 /* MatchListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFBF065D2BBD8040009D6715 /* MatchListView.swift */; }; FFBF06602BBD9F6D009D6715 /* NavigationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = FFBF065F2BBD9F6D009D6715 /* NavigationViewModel.swift */; }; @@ -1178,6 +1181,7 @@ FFB1C98A2C10255100B154A7 /* TournamentBroadcastRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TournamentBroadcastRowView.swift; sourceTree = ""; }; FFB9C8702BBADDE200A0EF4F /* Selectable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Selectable.swift; sourceTree = ""; }; FFB9C8742BBADDF700A0EF4F /* SeedInterval.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SeedInterval.swift; sourceTree = ""; }; + FFBE62042CE9DA0900815D33 /* MatchViewStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatchViewStyle.swift; sourceTree = ""; }; FFBF065B2BBD2657009D6715 /* GroupStageTeamView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupStageTeamView.swift; sourceTree = ""; }; FFBF065D2BBD8040009D6715 /* MatchListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatchListView.swift; sourceTree = ""; }; FFBF065F2BBD9F6D009D6715 /* NavigationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavigationViewModel.swift; sourceTree = ""; }; @@ -1733,6 +1737,7 @@ FFCFC01B2BBC5AAA00B82851 /* SetDescriptor.swift */, FFBF065F2BBD9F6D009D6715 /* NavigationViewModel.swift */, FF5BAF6D2BE0B3C8008B4B7E /* FederalDataViewModel.swift */, + FFBE62042CE9DA0900815D33 /* MatchViewStyle.swift */, ); path = ViewModel; sourceTree = ""; @@ -2321,6 +2326,7 @@ FF025AE12BD0EB9000A86CF8 /* TournamentClubSettingsView.swift in Sources */, FFBF065C2BBD2657009D6715 /* GroupStageTeamView.swift in Sources */, FF5DA1932BB9279B00A33061 /* RoundSettingsView.swift in Sources */, + FFBE62052CE9DA0900815D33 /* MatchViewStyle.swift in Sources */, FFE2D2E22C231BEE00D0C7BE /* SupportButtonView.swift in Sources */, FFB1C98B2C10255100B154A7 /* TournamentBroadcastRowView.swift in Sources */, FF025ADF2BD0CE0A00A86CF8 /* TeamWeightView.swift in Sources */, @@ -2605,6 +2611,7 @@ FF4CBF5A2C996C0600151637 /* TournamentClubSettingsView.swift in Sources */, FF4CBF5B2C996C0600151637 /* GroupStageTeamView.swift in Sources */, FF4CBF5C2C996C0600151637 /* RoundSettingsView.swift in Sources */, + FFBE62072CE9DA0900815D33 /* MatchViewStyle.swift in Sources */, FF4CBF5D2C996C0600151637 /* SupportButtonView.swift in Sources */, FF4CBF5E2C996C0600151637 /* TournamentBroadcastRowView.swift in Sources */, FF4CBF5F2C996C0600151637 /* TeamWeightView.swift in Sources */, @@ -2868,6 +2875,7 @@ FF70FAD92C90584900129CC2 /* TournamentClubSettingsView.swift in Sources */, FF70FADA2C90584900129CC2 /* GroupStageTeamView.swift in Sources */, FF70FADB2C90584900129CC2 /* RoundSettingsView.swift in Sources */, + FFBE62062CE9DA0900815D33 /* MatchViewStyle.swift in Sources */, FF70FADC2C90584900129CC2 /* SupportButtonView.swift in Sources */, FF70FADD2C90584900129CC2 /* TournamentBroadcastRowView.swift in Sources */, FF70FADE2C90584900129CC2 /* TeamWeightView.swift in Sources */, diff --git a/PadelClub/Data/Match.swift b/PadelClub/Data/Match.swift index 7bd6547..9084607 100644 --- a/PadelClub/Data/Match.swift +++ b/PadelClub/Data/Match.swift @@ -975,19 +975,18 @@ defer { return confirmed == false && startDate.timeIntervalSinceNow < 0 } - func expectedFormattedStartDate(updatedField: Int?) -> String { + func expectedFormattedStartDate(canBePlayedInSpecifiedCourt: Bool, availableCourts: [Int], estimatedStartDate: CourtIndexAndDate?, updatedField: Int?) -> String { guard let startDate else { return "" } guard hasEnded() == false, isRunning() == false else { return "" } let depthReadiness = depthReadiness() if depthReadiness == 0 { - let availableCourts = availableCourts() - if canBePlayedInSpecifiedCourt() { + if canBePlayedInSpecifiedCourt { return "possible tout de suite" } else if let updatedField, availableCourts.contains(updatedField) { return "possible tout de suite \(courtName(for: updatedField))" } else if let first = availableCourts.first { return "possible tout de suite \(courtName(for: first))" - } else if let estimatedStartDate = estimatedStartDate() { + } else if let estimatedStartDate { return "dans ~" + estimatedStartDate.1.timeElapsedString() + " " + courtName(for: estimatedStartDate.0) } return "était prévu à " + startDate.formattedAsHourMinute() @@ -1014,10 +1013,8 @@ defer { typealias CourtIndexAndDate = (courtIndex: Int, startDate: Date) - func nextCourtsAvailable() -> [CourtIndexAndDate] { + func nextCourtsAvailable(availableCourts: [Int], runningMatches: [Match]) -> [CourtIndexAndDate] { guard let tournament = currentTournament() else { return [] } - let availableCourts = availableCourts() - let runningMatches = Tournament.runningMatches(tournament.allMatches()) let startDate = Date().withoutSeconds() if runningMatches.isEmpty { return availableCourts.map { @@ -1041,10 +1038,10 @@ defer { return dates } - func estimatedStartDate() -> CourtIndexAndDate? { + func estimatedStartDate(availableCourts: [Int], runningMatches: [Match]) -> CourtIndexAndDate? { guard isReady() else { return nil } guard let tournament = currentTournament() else { return nil } - let availableCourts = nextCourtsAvailable() + let availableCourts = nextCourtsAvailable(availableCourts: availableCourts, runningMatches: runningMatches) return availableCourts.first(where: { (courtIndex, startDate) in let endDate = startDate.addingTimeInterval(TimeInterval(matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) * 60) if tournament.courtUnavailable(courtIndex: courtIndex, from: startDate, to: endDate) == false { diff --git a/PadelClub/Data/PlayerRegistration.swift b/PadelClub/Data/PlayerRegistration.swift index d137e2d..4dbc043 100644 --- a/PadelClub/Data/PlayerRegistration.swift +++ b/PadelClub/Data/PlayerRegistration.swift @@ -188,6 +188,10 @@ final class PlayerRegistration: ModelObject, Storable { return self.tournamentStore.teamRegistrations.findById(teamRegistration) } + func isHere() -> Bool { + hasArrived + } + func hasPaid() -> Bool { paymentType != nil } diff --git a/PadelClub/Utils/DisplayContext.swift b/PadelClub/Utils/DisplayContext.swift index 7eafd7d..e9d0338 100644 --- a/PadelClub/Utils/DisplayContext.swift +++ b/PadelClub/Utils/DisplayContext.swift @@ -26,32 +26,6 @@ enum SummoningDisplayContext { case menu } -enum MatchViewStyle { - case standardStyle // vue normal - case sectionedStandardStyle // vue normal avec des sections indiquant déjà la manche - case feedStyle // vue programmation - case plainStyle // vue detail - case tournamentResultStyle //vue resultat tournoi - case followUpStyle // vue normal - - func displayRestingTime() -> Bool { - switch self { - case .standardStyle: - return false - case .sectionedStandardStyle: - return false - case .feedStyle: - return false - case .plainStyle: - return false - case .tournamentResultStyle: - return false - case .followUpStyle: - return true - } - } -} - struct DeviceHelper { static func isBigScreen() -> Bool { switch UIDevice.current.userInterfaceIdiom { diff --git a/PadelClub/ViewModel/MatchViewStyle.swift b/PadelClub/ViewModel/MatchViewStyle.swift new file mode 100644 index 0000000..5917fc7 --- /dev/null +++ b/PadelClub/ViewModel/MatchViewStyle.swift @@ -0,0 +1,51 @@ +// +// MatchViewStyle.swift +// PadelClub +// +// Created by razmig on 17/11/2024. +// + +import SwiftUI + +enum MatchViewStyle { + case standardStyle // vue normal + case sectionedStandardStyle // vue normal avec des sections indiquant déjà la manche + case feedStyle // vue programmation + case plainStyle // vue detail + //case tournamentResultStyle //vue resultat tournoi + case followUpStyle // vue normal + + func displayRestingTime() -> Bool { + switch self { + case .standardStyle: + return false + case .sectionedStandardStyle: + return false + case .feedStyle: + return false + case .plainStyle: + return false +// case .tournamentResultStyle: +// return false + case .followUpStyle: + return true + } + } +} + +struct MatchViewStyleKey: EnvironmentKey { + static let defaultValue: MatchViewStyle = .standardStyle +} + +extension EnvironmentValues { + var matchViewStyle: MatchViewStyle { + get { self[MatchViewStyleKey.self] } + set { self[MatchViewStyleKey.self] = newValue } + } +} + +extension View { + func matchViewStyle(_ style: MatchViewStyle) -> some View { + environment(\.matchViewStyle, style) + } +} diff --git a/PadelClub/Views/Components/MatchListView.swift b/PadelClub/Views/Components/MatchListView.swift index c084661..0f98f01 100644 --- a/PadelClub/Views/Components/MatchListView.swift +++ b/PadelClub/Views/Components/MatchListView.swift @@ -10,10 +10,10 @@ import SwiftUI struct MatchListView: View { @EnvironmentObject var dataStore: DataStore + @Environment(\.matchViewStyle) private var matchViewStyle let section: String let matches: [Match]? - var matchViewStyle: MatchViewStyle = .standardStyle var hideWhenEmpty: Bool = false @State var isExpanded: Bool = true @@ -32,7 +32,7 @@ struct MatchListView: View { DisclosureGroup(isExpanded: $isExpanded) { if let matches { ForEach(matches) { match in - MatchRowView(match: match, matchViewStyle: matchViewStyle) + MatchRowView(match: match) .listRowInsets(EdgeInsets(top: 0, leading: -2, bottom: 0, trailing: 8)) } } diff --git a/PadelClub/Views/GroupStage/GroupStagesView.swift b/PadelClub/Views/GroupStage/GroupStagesView.swift index f3e2a58..13cd9e2 100644 --- a/PadelClub/Views/GroupStage/GroupStagesView.swift +++ b/PadelClub/Views/GroupStage/GroupStagesView.swift @@ -146,23 +146,25 @@ struct GroupStagesView: View { let runningMatches = Tournament.runningMatches(allMatches) Section { - MatchListView(section: "en cours", matches: runningMatches, matchViewStyle: .standardStyle, isExpanded: false) + MatchListView(section: "en cours", matches: runningMatches, isExpanded: false) } Section { - MatchListView(section: "prêt à démarrer", matches: Tournament.availableToStart(allMatches, in: runningMatches), matchViewStyle: .standardStyle, isExpanded: false) + MatchListView(section: "prêt à démarrer", matches: Tournament.availableToStart(allMatches, in: runningMatches), isExpanded: false) + } Section { - MatchListView(section: "à lancer", matches: Tournament.readyMatches(allMatches), matchViewStyle: .standardStyle, isExpanded: false) + MatchListView(section: "à lancer", matches: Tournament.readyMatches(allMatches), isExpanded: false) } Section { - MatchListView(section: "terminés", matches: finishedMatches, matchViewStyle: .standardStyle, isExpanded: false) + MatchListView(section: "terminés", matches: finishedMatches, isExpanded: false) } } + .matchViewStyle(.standardStyle) .navigationTitle("Toutes les poules") case .groupStage(let groupStage): GroupStageView(groupStage: groupStage).id(groupStage.id) diff --git a/PadelClub/Views/GroupStage/LoserBracketFromGroupStageView.swift b/PadelClub/Views/GroupStage/LoserBracketFromGroupStageView.swift index aeb532a..bd0fe30 100644 --- a/PadelClub/Views/GroupStage/LoserBracketFromGroupStageView.swift +++ b/PadelClub/Views/GroupStage/LoserBracketFromGroupStageView.swift @@ -45,7 +45,8 @@ struct LoserBracketFromGroupStageView: View { ForEach(displayableMatches) { match in Section { - MatchRowView(match: match, matchViewStyle: .sectionedStandardStyle) + MatchRowView(match: match) + .matchViewStyle(.sectionedStandardStyle) .environment(\.isEditingTournamentSeed, $isEditingLoserBracketGroupStage) } header: { let tournamentTeamCount = tournament.teamCount diff --git a/PadelClub/Views/Match/Components/MatchDateView.swift b/PadelClub/Views/Match/Components/MatchDateView.swift index 9d33fe2..51ccc19 100644 --- a/PadelClub/Views/Match/Components/MatchDateView.swift +++ b/PadelClub/Views/Match/Components/MatchDateView.swift @@ -26,13 +26,7 @@ struct MatchDateView: View { self.isReady = match.isReady() self.hasWalkoutTeam = match.hasWalkoutTeam() self.hasEnded = match.hasEnded() - if updatedField == nil, match.canBePlayedInSpecifiedCourt() { - self.updatedField = match.courtIndex - } else if let updatedField { - self.updatedField = updatedField - } else { - self.updatedField = match.availableCourts().first - } + self.updatedField = updatedField } var currentDate: Date { diff --git a/PadelClub/Views/Match/Components/PlayerBlockView.swift b/PadelClub/Views/Match/Components/PlayerBlockView.swift index 5813ab9..c98a724 100644 --- a/PadelClub/Views/Match/Components/PlayerBlockView.swift +++ b/PadelClub/Views/Match/Components/PlayerBlockView.swift @@ -8,26 +8,29 @@ import SwiftUI struct PlayerBlockView: View { + @Environment(\.matchViewStyle) private var matchViewStyle @State var match: Match let teamPosition: TeamPosition let team: TeamRegistration? - let color: Color - let width: CGFloat let teamScore: TeamScore? let isWalkOut: Bool - let displayRestingTime: Bool - init(match: Match, teamPosition: TeamPosition, color: Color, width: CGFloat, displayRestingTime: Bool) { + var displayRestingTime: Bool { + matchViewStyle.displayRestingTime() + } + + var width: CGFloat { + matchViewStyle == .plainStyle ? 1 : 2 + } + + init(match: Match, teamPosition: TeamPosition) { self.match = match self.teamPosition = teamPosition let theTeam = match.team(teamPosition) self.team = theTeam - self.color = color - self.width = width let theTeamScore = match.teamScore(ofTeam: theTeam) self.teamScore = theTeamScore self.isWalkOut = theTeamScore?.isWalkOut() == true - self.displayRestingTime = displayRestingTime } var names: [String]? { @@ -81,8 +84,8 @@ struct PlayerBlockView: View { } ForEach(team.players()) { player in Text(player.playerLabel()).lineLimit(1) - .italic(player.hasArrived == false) - .foregroundStyle(player.hasArrived == false ? .secondary : .primary) + .italic(player.isHere() == false) + .foregroundStyle(player.isHere() == false ? .secondary : .primary) } } else { ZStack(alignment: .leading) { @@ -122,7 +125,7 @@ struct PlayerBlockView: View { if width == 1 { Divider() } else { - Divider().frame(width: width).overlay(color) + Divider().frame(width: width).overlay(Color(white: 0.9)) } Text(string) .font(.title3) diff --git a/PadelClub/Views/Match/MatchDetailView.swift b/PadelClub/Views/Match/MatchDetailView.swift index 4adaa02..45f0444 100644 --- a/PadelClub/Views/Match/MatchDetailView.swift +++ b/PadelClub/Views/Match/MatchDetailView.swift @@ -14,8 +14,8 @@ struct MatchDetailView: View { @EnvironmentObject var networkMonitor: NetworkMonitor @Environment(\.dismiss) var dismiss - let matchViewStyle: MatchViewStyle - + @Environment(\.matchViewStyle) private var matchViewStyle + @State private var showLiveScore: Bool = false @State private var editScore: Bool = false @State private var scoreType: ScoreType? @@ -54,9 +54,8 @@ struct MatchDetailView: View { var match: Match - init(match: Match, matchViewStyle: MatchViewStyle = .standardStyle, updatedField: Int? = nil) { + init(match: Match, updatedField: Int? = nil) { self.match = match - self.matchViewStyle = matchViewStyle if match.hasStarted() == false && (match.startDate == nil || match.courtIndex == nil) { _isEditing = State(wrappedValue: true) @@ -89,7 +88,8 @@ struct MatchDetailView: View { } Section { - MatchSummaryView(match: match, matchViewStyle: .plainStyle) + MatchSummaryView(match: match) + .matchViewStyle(.plainStyle) } footer: { if match.isEmpty() == false { HStack { diff --git a/PadelClub/Views/Match/MatchRowView.swift b/PadelClub/Views/Match/MatchRowView.swift index 1a778c1..643078e 100644 --- a/PadelClub/Views/Match/MatchRowView.swift +++ b/PadelClub/Views/Match/MatchRowView.swift @@ -11,8 +11,8 @@ import LeStorage struct MatchRowView: View { @EnvironmentObject var dataStore: DataStore + @Environment(\.matchViewStyle) private var matchViewStyle @State var match: Match - let matchViewStyle: MatchViewStyle var title: String? = nil var updatedField: Int? = nil @@ -60,9 +60,9 @@ struct MatchRowView: View { // }) NavigationLink { - MatchDetailView(match: match, matchViewStyle: matchViewStyle, updatedField: updatedField) + MatchDetailView(match: match, updatedField: updatedField) } label: { - MatchSummaryView(match: match, matchViewStyle: matchViewStyle, title: title, updatedField: updatedField) + MatchSummaryView(match: match, title: title, updatedField: updatedField) .contextMenu { Section { ForEach(match.teams().flatMap({ $0.players() })) { player in diff --git a/PadelClub/Views/Match/MatchSummaryView.swift b/PadelClub/Views/Match/MatchSummaryView.swift index 5e3a86f..cdb7471 100644 --- a/PadelClub/Views/Match/MatchSummaryView.swift +++ b/PadelClub/Views/Match/MatchSummaryView.swift @@ -10,30 +10,25 @@ import SwiftUI struct MatchSummaryView: View { @EnvironmentObject var dataStore: DataStore @State var match: Match - let matchViewStyle: MatchViewStyle + @Environment(\.matchViewStyle) private var matchViewStyle let matchTitle: String let roundTitle: String? let courtName: String? - let spacing: CGFloat - let padding: CGFloat - let color: Color - let width: CGFloat let updatedField: Int? let estimatedStartDate: Match.CourtIndexAndDate? + let availableCourts: [Int] + let canBePlayedInSpecifiedCourt: Bool - init(match: Match, matchViewStyle: MatchViewStyle, title: String? = nil, updatedField: Int? = nil) { + init(match: Match, title: String? = nil, updatedField: Int? = nil) { self.match = match - self.matchViewStyle = matchViewStyle - self.padding = matchViewStyle == .plainStyle ? 0 : 8 - self.spacing = matchViewStyle == .plainStyle ? 8 : 0 - self.width = matchViewStyle == .plainStyle ? 1 : 2 - self.color = Color(white: 0.9) self.updatedField = updatedField + let currentAvailableCourts = match.availableCourts() + self.availableCourts = currentAvailableCourts if let groupStage = match.groupStageObject { self.roundTitle = groupStage.groupStageTitle(.title) } else if let round = match.roundObject { - self.roundTitle = round.roundTitle(matchViewStyle == .feedStyle ? .wide : .short) + self.roundTitle = round.roundTitle(.short) } else { self.roundTitle = nil } @@ -45,10 +40,23 @@ struct MatchSummaryView: View { } else { self.courtName = nil } - - self.estimatedStartDate = match.estimatedStartDate() + let runningMatches = Tournament.runningMatches(match.currentTournament()?.allMatches() ?? []) + self.estimatedStartDate = match.estimatedStartDate(availableCourts: currentAvailableCourts, runningMatches: runningMatches) + self.canBePlayedInSpecifiedCourt = match.canBePlayedInSpecifiedCourt() + } + + var spacing: CGFloat { + matchViewStyle == .plainStyle ? 8 : 0 + } + + var padding: CGFloat { + matchViewStyle == .plainStyle ? 0 : 8 } + var width: CGFloat { + matchViewStyle == .plainStyle ? 1 : 2 + } + var body: some View { VStack(alignment: .leading) { if matchViewStyle != .plainStyle { @@ -76,33 +84,35 @@ struct MatchSummaryView: View { HStack(spacing: 0) { VStack(alignment: .leading, spacing: spacing) { - PlayerBlockView(match: match, teamPosition: .one, color: color, width: width, displayRestingTime: matchViewStyle.displayRestingTime()) + PlayerBlockView(match: match, teamPosition: .one) .padding(padding) if width == 1 { Divider() } else { - Divider().frame(height: width).overlay(color) + Divider().frame(height: width).overlay(Color(white: 0.9)) } - PlayerBlockView(match: match, teamPosition: .two, color: color, width: width, displayRestingTime: matchViewStyle.displayRestingTime()) + PlayerBlockView(match: match, teamPosition: .two) .padding(padding) } } .overlay { if matchViewStyle != .plainStyle { RoundedRectangle(cornerRadius: 8) - .stroke(color, lineWidth: 2) + .stroke(Color(white: 0.9), lineWidth: 2) } } if matchViewStyle != .plainStyle { HStack { - if match.expectedToBeRunning() { - Text(match.expectedFormattedStartDate(updatedField: updatedField)) - .font(.footnote) - .foregroundStyle(.secondary) + if matchViewStyle == .followUpStyle { + if match.expectedToBeRunning() { + Text(match.expectedFormattedStartDate(canBePlayedInSpecifiedCourt: canBePlayedInSpecifiedCourt, availableCourts: availableCourts, estimatedStartDate: estimatedStartDate, updatedField: updatedField)) + .font(.footnote) + .foregroundStyle(.secondary) + } } Spacer() - MatchDateView(match: match, showPrefix: matchViewStyle == .tournamentResultStyle, updatedField: possibleCourtIndex) + MatchDateView(match: match, showPrefix: false, updatedField: possibleCourtIndex) } } } @@ -111,8 +121,7 @@ struct MatchSummaryView: View { } var possibleCourtIndex: Int? { - let availableCourts = match.availableCourts() - if match.canBePlayedInSpecifiedCourt() { + if canBePlayedInSpecifiedCourt { return nil } else if let updatedField, availableCourts.contains(updatedField) { return updatedField @@ -133,7 +142,7 @@ struct MatchSummaryView: View { return false } - if match.canBePlayedInSpecifiedCourt() { + if canBePlayedInSpecifiedCourt { return false } diff --git a/PadelClub/Views/Navigation/Ongoing/OngoingView.swift b/PadelClub/Views/Navigation/Ongoing/OngoingView.swift index 4335f39..309885a 100644 --- a/PadelClub/Views/Navigation/Ongoing/OngoingView.swift +++ b/PadelClub/Views/Navigation/Ongoing/OngoingView.swift @@ -32,7 +32,8 @@ struct OngoingView: View { ForEach(filteredMatches) { match in let tournament = match.currentTournament() Section { - MatchRowView(match: match, matchViewStyle: .standardStyle) + MatchRowView(match: match) + .matchViewStyle(.followUpStyle) } header: { if let tournament { HStack { diff --git a/PadelClub/Views/Planning/PlanningByCourtView.swift b/PadelClub/Views/Planning/PlanningByCourtView.swift index 15a1a9e..10b4f92 100644 --- a/PadelClub/Views/Planning/PlanningByCourtView.swift +++ b/PadelClub/Views/Planning/PlanningByCourtView.swift @@ -112,7 +112,8 @@ struct PlanningByCourtView: View { ForEach(_sortedMatches.indices, id: \.self) { index in let match = _sortedMatches[index] Section { - MatchRowView(match: match, matchViewStyle: .feedStyle) + MatchRowView(match: match) + .matchViewStyle(.feedStyle) } header: { if let startDate = match.startDate { if index > 0 { diff --git a/PadelClub/Views/Planning/PlanningView.swift b/PadelClub/Views/Planning/PlanningView.swift index 1e738b6..3a6e07f 100644 --- a/PadelClub/Views/Planning/PlanningView.swift +++ b/PadelClub/Views/Planning/PlanningView.swift @@ -158,7 +158,9 @@ struct PlanningView: View { DisclosureGroup { ForEach(_matches) { match in NavigationLink { - MatchDetailView(match: match, matchViewStyle: .sectionedStandardStyle) + MatchDetailView(match: match) + .matchViewStyle(.sectionedStandardStyle) + } label: { LabeledContent { if let courtName = match.courtName() { diff --git a/PadelClub/Views/Round/LoserRoundView.swift b/PadelClub/Views/Round/LoserRoundView.swift index 843765d..fba3563 100644 --- a/PadelClub/Views/Round/LoserRoundView.swift +++ b/PadelClub/Views/Round/LoserRoundView.swift @@ -40,7 +40,8 @@ struct LoserRoundView: View { if matches.isEmpty == false { Section { ForEach(matches) { match in - MatchRowView(match: match, 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 68c0418..23bf3d5 100644 --- a/PadelClub/Views/Round/RoundView.swift +++ b/PadelClub/Views/Round/RoundView.swift @@ -215,7 +215,8 @@ struct RoundView: View { ForEach(displayableMatches) { match in let matchTitle = match.matchTitle(.short, inMatches: displayableMatches) Section { - MatchRowView(match: match, matchViewStyle: .sectionedStandardStyle, title: matchTitle) + MatchRowView(match: match, title: matchTitle) + .matchViewStyle(.sectionedStandardStyle) } header: { HStack { Text(upperRound.round.roundTitle(.wide)) diff --git a/PadelClub/Views/Score/FollowUpMatchView.swift b/PadelClub/Views/Score/FollowUpMatchView.swift index 0ee7f20..78cda7f 100644 --- a/PadelClub/Views/Score/FollowUpMatchView.swift +++ b/PadelClub/Views/Score/FollowUpMatchView.swift @@ -198,7 +198,8 @@ struct FollowUpMatchView: View { ForEach(sortedMatches) { match in let tournament = match.currentTournament() Section { - MatchRowView(match: match, matchViewStyle: .followUpStyle, updatedField: selectedCourt) + MatchRowView(match: match, updatedField: selectedCourt) + .matchViewStyle(.followUpStyle) } header: { if let tournament { HStack { diff --git a/PadelClub/Views/Team/TeamRestingView.swift b/PadelClub/Views/Team/TeamRestingView.swift index 1438f59..712cb05 100644 --- a/PadelClub/Views/Team/TeamRestingView.swift +++ b/PadelClub/Views/Team/TeamRestingView.swift @@ -62,7 +62,8 @@ struct TeamRestingView: View { case .restingTime: if sortedMatches.isEmpty == false { ForEach(sortedMatches) { match in - MatchRowView(match: match, matchViewStyle: .followUpStyle, updatedField: selectedCourt) + MatchRowView(match: match, updatedField: selectedCourt) + .matchViewStyle(.followUpStyle) } } else { ContentUnavailableView("Aucun match à venir", systemImage: "xmark.circle", description: Text(contentUnavailableDescriptionLabel()))