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] {
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? {

@ -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)
}

@ -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 {

@ -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)
}

Loading…
Cancel
Save