From a7bd1903130c83e13f920084ec769a36e9e95748 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Sun, 26 May 2024 13:04:53 +0200 Subject: [PATCH] attempt to fix lag stuff --- PadelClub/Data/GroupStage.swift | 7 ++++--- PadelClub/Data/Tournament.swift | 8 ++++++-- PadelClub/Views/GroupStage/GroupStageView.swift | 4 ++-- PadelClub/Views/GroupStage/GroupStagesView.swift | 6 +++--- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/PadelClub/Data/GroupStage.swift b/PadelClub/Data/GroupStage.swift index 29e48bb..c8f5463 100644 --- a/PadelClub/Data/GroupStage.swift +++ b/PadelClub/Data/GroupStage.swift @@ -171,11 +171,12 @@ class GroupStage: ModelObject, Storable { } func availableToStart(playedMatches: [Match], in runningMatches: [Match]) -> [Match] { + return [] return playedMatches.filter({ $0.canBeStarted(inMatches: runningMatches) && $0.isRunning() == false }) } func runningMatches(playedMatches: [Match]) -> [Match] { - playedMatches.filter({ $0.isRunning() }) + playedMatches.filter({ $0.isRunning() }).sorted(by: \.computedStartDateForSorting) } func readyMatches(playedMatches: [Match]) -> [Match] { @@ -183,7 +184,7 @@ class GroupStage: ModelObject, Storable { } func finishedMatches(playedMatches: [Match]) -> [Match] { - playedMatches.filter({ $0.hasEnded() }) + playedMatches.filter({ $0.hasEnded() }).sorted(by: \.computedEndDateForSorting).reversed() } private func _matchOrder() -> [Int] { @@ -365,7 +366,7 @@ extension GroupStage: Selectable { } func badgeValue() -> Int? { - runningMatches(playedMatches: playedMatches()).count + runningMatches(playedMatches: _matches()).count } func badgeValueColor() -> Color? { diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index 1f82dcd..db7d353 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -929,8 +929,12 @@ class Tournament : ModelObject, Storable { return Calendar.current.compare(summonDate, to: expectedSummonDate, toGranularity: .minute) != ComparisonResult.orderedSame } - func availableToStart(_ allMatches: [Match]) -> [Match] { - let runningMatches = allMatches.filter({ $0.isRunning() && $0.isReady() }) + func groupStagesMatches() -> [Match] { + let groupStageIds = groupStages().map { $0.id } + return Store.main.filter(isIncluded: { $0.groupStage != nil && groupStageIds.contains($0.groupStage!) }) + } + + func availableToStart(_ allMatches: [Match], in runningMatches: [Match]) -> [Match] { return allMatches.filter({ $0.canBeStarted(inMatches: runningMatches) && $0.isRunning() == false }).sorted(by: \.computedStartDateForSorting) } diff --git a/PadelClub/Views/GroupStage/GroupStageView.swift b/PadelClub/Views/GroupStage/GroupStageView.swift index 92c8c4c..0500678 100644 --- a/PadelClub/Views/GroupStage/GroupStageView.swift +++ b/PadelClub/Views/GroupStage/GroupStageView.swift @@ -15,13 +15,11 @@ struct GroupStageView: View { @State private var sortingMode: GroupStageSortingMode = .auto @State private var confirmRemoveAll: Bool = false @State private var confirmResetMatch: Bool = false - @State private var groupStageName: String = "" let playedMatches: [Match] init(groupStage: GroupStage) { self.groupStage = groupStage self.playedMatches = groupStage.playedMatches() - _groupStageName = State(wrappedValue: groupStage.groupStageTitle()) } var body: some View { @@ -224,6 +222,7 @@ struct GroupStageView: View { } struct GroupStageNameEditionView: View { + @Environment(\.dismiss) private var dismiss @EnvironmentObject var dataStore: DataStore let groupStage: GroupStage @State private var groupStageName: String = "" @@ -241,6 +240,7 @@ struct GroupStageNameEditionView: View { groupStageName = groupStageName.trimmed groupStage.name = groupStageName _save() + dismiss() } } footer: { HStack { diff --git a/PadelClub/Views/GroupStage/GroupStagesView.swift b/PadelClub/Views/GroupStage/GroupStagesView.swift index fc1c9f6..28753ac 100644 --- a/PadelClub/Views/GroupStage/GroupStagesView.swift +++ b/PadelClub/Views/GroupStage/GroupStagesView.swift @@ -55,7 +55,7 @@ struct GroupStagesView: View { init(tournament: Tournament) { self.tournament = tournament - self.allMatches = tournament.groupStages().flatMap({ $0.playedMatches() }) + self.allMatches = tournament.groupStagesMatches() if tournament.shouldVerifyGroupStage { _selectedDestination = State(wrappedValue: nil) @@ -81,14 +81,14 @@ struct GroupStagesView: View { GenericDestinationPickerView(selectedDestination: $selectedDestination, destinations: allDestinations(), nilDestinationIsValid: true) switch selectedDestination { case .all: - let availableToStart = tournament.availableToStart(allMatches) let runningMatches = tournament.runningMatches(allMatches) + let availableToStart = tournament.availableToStart(allMatches, in: runningMatches) let readyMatches = tournament.readyMatches(allMatches) let finishedMatches = tournament.finishedMatches(allMatches) List { - MatchListView(section: "disponible", matches: availableToStart, matchViewStyle: .standardStyle, isExpanded: false) MatchListView(section: "en cours", matches: runningMatches, matchViewStyle: .standardStyle, isExpanded: false) + MatchListView(section: "disponible", matches: availableToStart, matchViewStyle: .standardStyle, isExpanded: false) MatchListView(section: "à lancer", matches: readyMatches, matchViewStyle: .standardStyle, isExpanded: false) MatchListView(section: "terminés", matches: finishedMatches, matchViewStyle: .standardStyle, isExpanded: false) }