attempt to fix lag stuff

multistore
Razmig Sarkissian 1 year ago
parent 7c5ba47f72
commit a7bd190313
  1. 7
      PadelClub/Data/GroupStage.swift
  2. 8
      PadelClub/Data/Tournament.swift
  3. 4
      PadelClub/Views/GroupStage/GroupStageView.swift
  4. 6
      PadelClub/Views/GroupStage/GroupStagesView.swift

@ -171,11 +171,12 @@ class GroupStage: ModelObject, Storable {
} }
func availableToStart(playedMatches: [Match], in runningMatches: [Match]) -> [Match] { func availableToStart(playedMatches: [Match], in runningMatches: [Match]) -> [Match] {
return []
return playedMatches.filter({ $0.canBeStarted(inMatches: runningMatches) && $0.isRunning() == false }) return playedMatches.filter({ $0.canBeStarted(inMatches: runningMatches) && $0.isRunning() == false })
} }
func runningMatches(playedMatches: [Match]) -> [Match] { func runningMatches(playedMatches: [Match]) -> [Match] {
playedMatches.filter({ $0.isRunning() }) playedMatches.filter({ $0.isRunning() }).sorted(by: \.computedStartDateForSorting)
} }
func readyMatches(playedMatches: [Match]) -> [Match] { func readyMatches(playedMatches: [Match]) -> [Match] {
@ -183,7 +184,7 @@ class GroupStage: ModelObject, Storable {
} }
func finishedMatches(playedMatches: [Match]) -> [Match] { func finishedMatches(playedMatches: [Match]) -> [Match] {
playedMatches.filter({ $0.hasEnded() }) playedMatches.filter({ $0.hasEnded() }).sorted(by: \.computedEndDateForSorting).reversed()
} }
private func _matchOrder() -> [Int] { private func _matchOrder() -> [Int] {
@ -365,7 +366,7 @@ extension GroupStage: Selectable {
} }
func badgeValue() -> Int? { func badgeValue() -> Int? {
runningMatches(playedMatches: playedMatches()).count runningMatches(playedMatches: _matches()).count
} }
func badgeValueColor() -> Color? { func badgeValueColor() -> Color? {

@ -929,8 +929,12 @@ class Tournament : ModelObject, Storable {
return Calendar.current.compare(summonDate, to: expectedSummonDate, toGranularity: .minute) != ComparisonResult.orderedSame return Calendar.current.compare(summonDate, to: expectedSummonDate, toGranularity: .minute) != ComparisonResult.orderedSame
} }
func availableToStart(_ allMatches: [Match]) -> [Match] { func groupStagesMatches() -> [Match] {
let runningMatches = allMatches.filter({ $0.isRunning() && $0.isReady() }) 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) return allMatches.filter({ $0.canBeStarted(inMatches: runningMatches) && $0.isRunning() == false }).sorted(by: \.computedStartDateForSorting)
} }

@ -15,13 +15,11 @@ struct GroupStageView: View {
@State private var sortingMode: GroupStageSortingMode = .auto @State private var sortingMode: GroupStageSortingMode = .auto
@State private var confirmRemoveAll: Bool = false @State private var confirmRemoveAll: Bool = false
@State private var confirmResetMatch: Bool = false @State private var confirmResetMatch: Bool = false
@State private var groupStageName: String = ""
let playedMatches: [Match] let playedMatches: [Match]
init(groupStage: GroupStage) { init(groupStage: GroupStage) {
self.groupStage = groupStage self.groupStage = groupStage
self.playedMatches = groupStage.playedMatches() self.playedMatches = groupStage.playedMatches()
_groupStageName = State(wrappedValue: groupStage.groupStageTitle())
} }
var body: some View { var body: some View {
@ -224,6 +222,7 @@ struct GroupStageView: View {
} }
struct GroupStageNameEditionView: View { struct GroupStageNameEditionView: View {
@Environment(\.dismiss) private var dismiss
@EnvironmentObject var dataStore: DataStore @EnvironmentObject var dataStore: DataStore
let groupStage: GroupStage let groupStage: GroupStage
@State private var groupStageName: String = "" @State private var groupStageName: String = ""
@ -241,6 +240,7 @@ struct GroupStageNameEditionView: View {
groupStageName = groupStageName.trimmed groupStageName = groupStageName.trimmed
groupStage.name = groupStageName groupStage.name = groupStageName
_save() _save()
dismiss()
} }
} footer: { } footer: {
HStack { HStack {

@ -55,7 +55,7 @@ struct GroupStagesView: View {
init(tournament: Tournament) { init(tournament: Tournament) {
self.tournament = tournament self.tournament = tournament
self.allMatches = tournament.groupStages().flatMap({ $0.playedMatches() }) self.allMatches = tournament.groupStagesMatches()
if tournament.shouldVerifyGroupStage { if tournament.shouldVerifyGroupStage {
_selectedDestination = State(wrappedValue: nil) _selectedDestination = State(wrappedValue: nil)
@ -81,14 +81,14 @@ struct GroupStagesView: View {
GenericDestinationPickerView(selectedDestination: $selectedDestination, destinations: allDestinations(), nilDestinationIsValid: true) GenericDestinationPickerView(selectedDestination: $selectedDestination, destinations: allDestinations(), nilDestinationIsValid: true)
switch selectedDestination { switch selectedDestination {
case .all: case .all:
let availableToStart = tournament.availableToStart(allMatches)
let runningMatches = tournament.runningMatches(allMatches) let runningMatches = tournament.runningMatches(allMatches)
let availableToStart = tournament.availableToStart(allMatches, in: runningMatches)
let readyMatches = tournament.readyMatches(allMatches) let readyMatches = tournament.readyMatches(allMatches)
let finishedMatches = tournament.finishedMatches(allMatches) let finishedMatches = tournament.finishedMatches(allMatches)
List { List {
MatchListView(section: "disponible", matches: availableToStart, matchViewStyle: .standardStyle, isExpanded: false)
MatchListView(section: "en cours", matches: runningMatches, 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: "à lancer", matches: readyMatches, matchViewStyle: .standardStyle, isExpanded: false)
MatchListView(section: "terminés", matches: finishedMatches, matchViewStyle: .standardStyle, isExpanded: false) MatchListView(section: "terminés", matches: finishedMatches, matchViewStyle: .standardStyle, isExpanded: false)
} }

Loading…
Cancel
Save