From 9e8f7a4ecf821624fde8bcfec2b1a234d3574254 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Fri, 20 Jun 2025 15:12:01 +0200 Subject: [PATCH] fix planning stuff --- PadelClubData/Data/DataStore.swift | 9 ++++++++- PadelClubData/Data/Match.swift | 15 ++++++++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/PadelClubData/Data/DataStore.swift b/PadelClubData/Data/DataStore.swift index f81af68..5f1957b 100644 --- a/PadelClubData/Data/DataStore.swift +++ b/PadelClubData/Data/DataStore.swift @@ -106,6 +106,7 @@ public class DataStore: ObservableObject { if Store.main.fileCollectionsAllLoaded() { AutomaticPatcher.applyAllWhenApplicable() + self.resetOngoingCache() } } @@ -321,7 +322,13 @@ public class DataStore: ObservableObject { private var _lastRunningAndNextCheckDate: Date? = nil private var _cachedRunningAndNextMatches: [Match]? = nil - + + public func resetOngoingCache() { + _lastEndCheckDate = nil + _lastRunningCheckDate = nil + _lastRunningAndNextCheckDate = nil + } + public func runningAndNextMatches() -> [Match] { let dateNow : Date = Date() if let lastCheck = _lastRunningAndNextCheckDate, diff --git a/PadelClubData/Data/Match.swift b/PadelClubData/Data/Match.swift index 9e2985c..667eab6 100644 --- a/PadelClubData/Data/Match.swift +++ b/PadelClubData/Data/Match.swift @@ -31,6 +31,15 @@ final public class Match: BaseMatch, SideStorable { plannedStartDate = startDate } + public func updateStartDate(_ date: Date?, keepPlannedStartDate: Bool) { + DataStore.shared.resetOngoingCache() + let cachedPlannedStartDate = self.plannedStartDate + self.startDate = date + if keepPlannedStartDate { + self.plannedStartDate = cachedPlannedStartDate + } + } + // MARK: - public func setMatchName(_ serverName: String?) { @@ -194,7 +203,7 @@ defer { } public func cleanScheduleAndSave(_ targetStartDate: Date? = nil) { - startDate = targetStartDate + updateStartDate(targetStartDate, keepPlannedStartDate: true) confirmed = false endDate = nil followingMatch()?.cleanScheduleAndSave(nil) @@ -652,7 +661,7 @@ defer { public func validateMatch(fromStartDate: Date, toEndDate: Date, fieldSetup: MatchFieldSetup, forced: Bool = false) { if hasEnded() == false { - startDate = fromStartDate + updateStartDate(fromStartDate, keepPlannedStartDate: true) switch fieldSetup { case .fullRandom: @@ -669,7 +678,7 @@ defer { } } else { - startDate = fromStartDate + updateStartDate(fromStartDate, keepPlannedStartDate: true) endDate = toEndDate }