fix planning stuff

newoffer2025
Razmig Sarkissian 5 months ago
parent b0b2412a92
commit 9e8f7a4ecf
  1. 9
      PadelClubData/Data/DataStore.swift
  2. 15
      PadelClubData/Data/Match.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,

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

Loading…
Cancel
Save