fix planning stuff

newoffer2025
Razmig Sarkissian 5 months ago
parent b0b2412a92
commit 9e8f7a4ecf
  1. 7
      PadelClubData/Data/DataStore.swift
  2. 15
      PadelClubData/Data/Match.swift

@ -106,6 +106,7 @@ public class DataStore: ObservableObject {
if Store.main.fileCollectionsAllLoaded() { if Store.main.fileCollectionsAllLoaded() {
AutomaticPatcher.applyAllWhenApplicable() AutomaticPatcher.applyAllWhenApplicable()
self.resetOngoingCache()
} }
} }
@ -322,6 +323,12 @@ public class DataStore: ObservableObject {
private var _lastRunningAndNextCheckDate: Date? = nil private var _lastRunningAndNextCheckDate: Date? = nil
private var _cachedRunningAndNextMatches: [Match]? = nil private var _cachedRunningAndNextMatches: [Match]? = nil
public func resetOngoingCache() {
_lastEndCheckDate = nil
_lastRunningCheckDate = nil
_lastRunningAndNextCheckDate = nil
}
public func runningAndNextMatches() -> [Match] { public func runningAndNextMatches() -> [Match] {
let dateNow : Date = Date() let dateNow : Date = Date()
if let lastCheck = _lastRunningAndNextCheckDate, if let lastCheck = _lastRunningAndNextCheckDate,

@ -31,6 +31,15 @@ final public class Match: BaseMatch, SideStorable {
plannedStartDate = startDate 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: - // MARK: -
public func setMatchName(_ serverName: String?) { public func setMatchName(_ serverName: String?) {
@ -194,7 +203,7 @@ defer {
} }
public func cleanScheduleAndSave(_ targetStartDate: Date? = nil) { public func cleanScheduleAndSave(_ targetStartDate: Date? = nil) {
startDate = targetStartDate updateStartDate(targetStartDate, keepPlannedStartDate: true)
confirmed = false confirmed = false
endDate = nil endDate = nil
followingMatch()?.cleanScheduleAndSave(nil) followingMatch()?.cleanScheduleAndSave(nil)
@ -652,7 +661,7 @@ defer {
public func validateMatch(fromStartDate: Date, toEndDate: Date, fieldSetup: MatchFieldSetup, forced: Bool = false) { public func validateMatch(fromStartDate: Date, toEndDate: Date, fieldSetup: MatchFieldSetup, forced: Bool = false) {
if hasEnded() == false { if hasEnded() == false {
startDate = fromStartDate updateStartDate(fromStartDate, keepPlannedStartDate: true)
switch fieldSetup { switch fieldSetup {
case .fullRandom: case .fullRandom:
@ -669,7 +678,7 @@ defer {
} }
} else { } else {
startDate = fromStartDate updateStartDate(fromStartDate, keepPlannedStartDate: true)
endDate = toEndDate endDate = toEndDate
} }

Loading…
Cancel
Save