|
|
|
|
@ -15,31 +15,28 @@ class DataStore: ObservableObject { |
|
|
|
|
|
|
|
|
|
@Published var user: CustomUser = CustomUser.placeHolder() { |
|
|
|
|
didSet { |
|
|
|
|
let loggedUser = StoreCenter.main.userId != nil |
|
|
|
|
StoreCenter.main.collectionsCanSynchronize = loggedUser |
|
|
|
|
let loggedUser = StoreCenter.main.isAuthenticated |
|
|
|
|
|
|
|
|
|
if loggedUser { |
|
|
|
|
if self.user.id != self.userStorage.item()?.id { |
|
|
|
|
self.userStorage.setItemNoSync(self.user) |
|
|
|
|
if StoreCenter.main.collectionsCanSynchronize { |
|
|
|
|
StoreCenter.main.initialSynchronization() |
|
|
|
|
StoreCenter.main.initialSynchronization(clear: false) |
|
|
|
|
self._fixMissingClubCreatorIfNecessary(self.clubs) |
|
|
|
|
self._fixMissingEventCreatorIfNecessary(self.events) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
self._temporaryLocalUser.item = self.user |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate(set) var tournaments: StoredCollection<Tournament> |
|
|
|
|
fileprivate(set) var clubs: StoredCollection<Club> |
|
|
|
|
fileprivate(set) var courts: StoredCollection<Court> |
|
|
|
|
fileprivate(set) var events: StoredCollection<Event> |
|
|
|
|
fileprivate(set) var tournaments: SyncedCollection<Tournament> |
|
|
|
|
fileprivate(set) var clubs: SyncedCollection<Club> |
|
|
|
|
fileprivate(set) var courts: SyncedCollection<Court> |
|
|
|
|
fileprivate(set) var events: SyncedCollection<Event> |
|
|
|
|
fileprivate(set) var monthData: StoredCollection<MonthData> |
|
|
|
|
fileprivate(set) var dateIntervals: StoredCollection<DateInterval> |
|
|
|
|
fileprivate(set) var purchases: StoredCollection<Purchase> |
|
|
|
|
fileprivate(set) var dateIntervals: SyncedCollection<DateInterval> |
|
|
|
|
fileprivate(set) var purchases: SyncedCollection<Purchase> |
|
|
|
|
|
|
|
|
|
fileprivate var userStorage: StoredSingleton<CustomUser> |
|
|
|
|
|
|
|
|
|
@ -127,9 +124,9 @@ class DataStore: ObservableObject { |
|
|
|
|
|
|
|
|
|
if let userSingleton: StoredSingleton<CustomUser> = notification.object as? StoredSingleton<CustomUser> { |
|
|
|
|
self.user = userSingleton.item() ?? self._temporaryLocalUser.item ?? CustomUser.placeHolder() |
|
|
|
|
} else if let clubsCollection: StoredCollection<Club> = notification.object as? StoredCollection<Club> { |
|
|
|
|
} else if let clubsCollection: SyncedCollection<Club> = notification.object as? SyncedCollection<Club> { |
|
|
|
|
self._fixMissingClubCreatorIfNecessary(clubsCollection) |
|
|
|
|
} else if let eventsCollection: StoredCollection<Event> = notification.object as? StoredCollection<Event> { |
|
|
|
|
} else if let eventsCollection: SyncedCollection<Event> = notification.object as? SyncedCollection<Event> { |
|
|
|
|
self._fixMissingEventCreatorIfNecessary(eventsCollection) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -139,7 +136,7 @@ class DataStore: ObservableObject { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate func _fixMissingClubCreatorIfNecessary(_ clubsCollection: StoredCollection<Club>) { |
|
|
|
|
fileprivate func _fixMissingClubCreatorIfNecessary(_ clubsCollection: SyncedCollection<Club>) { |
|
|
|
|
for club in clubsCollection { |
|
|
|
|
if let userId = StoreCenter.main.userId, club.creator == nil { |
|
|
|
|
club.creator = userId |
|
|
|
|
@ -150,7 +147,7 @@ class DataStore: ObservableObject { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fileprivate func _fixMissingEventCreatorIfNecessary(_ eventsCollection: StoredCollection<Event>) { |
|
|
|
|
fileprivate func _fixMissingEventCreatorIfNecessary(_ eventsCollection: SyncedCollection<Event>) { |
|
|
|
|
for event in eventsCollection { |
|
|
|
|
if let userId = StoreCenter.main.userId, event.creator == nil { |
|
|
|
|
event.creator = userId |
|
|
|
|
@ -224,8 +221,6 @@ class DataStore: ObservableObject { |
|
|
|
|
|
|
|
|
|
fileprivate func _localDisconnect() { |
|
|
|
|
|
|
|
|
|
StoreCenter.main.collectionsCanSynchronize = false |
|
|
|
|
|
|
|
|
|
let tournamendIds: [String] = self.tournaments.map { $0.id } |
|
|
|
|
|
|
|
|
|
TournamentLibrary.shared.reset() |
|
|
|
|
|