fix loading issues

sync3
Laurent 5 months ago
parent 866d822ecd
commit 9bf546ac3d
  1. 22
      PadelClubData/Data/DataStore.swift
  2. 2
      PadelClubData/Data/GroupStage.swift
  3. 5
      PadelClubDataTests/SyncDataAccessTests.swift

@ -22,8 +22,8 @@ public class DataStore: ObservableObject {
if self.user.id != self.userStorage.item()?.id {
self.userStorage.setItemNoSync(self.user)
StoreCenter.main.initialSynchronization(clear: false)
self._fixMissingClubCreatorIfNecessary(self.clubs)
self._fixMissingEventCreatorIfNecessary(self.events)
self._fixMissingClubCreatorIfNecessary()
self._fixMissingEventCreatorIfNecessary()
}
} else {
self._temporaryLocalUser.item = self.user
@ -96,12 +96,12 @@ public class DataStore: ObservableObject {
@objc func collectionDidLoad(notification: Notification) {
if let userSingleton: StoredSingleton<CustomUser> = notification.object as? StoredSingleton<CustomUser> {
self.user = userSingleton.item() ?? self._temporaryLocalUser.item ?? CustomUser.placeHolder()
} else if let clubsCollection: SyncedCollection<Club> = notification.object as? SyncedCollection<Club> {
self._fixMissingClubCreatorIfNecessary(clubsCollection)
} else if let eventsCollection: SyncedCollection<Event> = notification.object as? SyncedCollection<Event> {
self._fixMissingEventCreatorIfNecessary(eventsCollection)
if let userSingleton: StoredCollection<CustomUser> = notification.object as? StoredCollection<CustomUser> {
self.user = userSingleton.first ?? self._temporaryLocalUser.item ?? CustomUser.placeHolder()
} else if let clubsCollection: StoredCollection<Club> = notification.object as? StoredCollection<Club> {
self._fixMissingClubCreatorIfNecessary()
} else if let eventsCollection: StoredCollection<Event> = notification.object as? StoredCollection<Event> {
self._fixMissingEventCreatorIfNecessary()
}
if Store.main.fileCollectionsAllLoaded() {
@ -110,10 +110,11 @@ public class DataStore: ObservableObject {
}
fileprivate func _fixMissingClubCreatorIfNecessary(_ clubsCollection: SyncedCollection<Club>) {
fileprivate func _fixMissingClubCreatorIfNecessary() {
if self.user.clubs.count > 0 { return }
let clubsCollection = DataStore.shared.clubs
for club in clubsCollection {
if let userId = StoreCenter.main.userId, club.creator == nil {
club.creator = userId
@ -124,7 +125,8 @@ public class DataStore: ObservableObject {
}
}
fileprivate func _fixMissingEventCreatorIfNecessary(_ eventsCollection: SyncedCollection<Event>) {
fileprivate func _fixMissingEventCreatorIfNecessary() {
let eventsCollection = DataStore.shared.events
for event in eventsCollection {
if let userId = StoreCenter.main.userId, event.creator == nil {
event.creator = userId

@ -608,7 +608,7 @@ final public class GroupStage: BaseGroupStage, SideStorable {
}
public func computedStartDate() -> Date? {
return _matches().sorted(by: \.computedStartDateForSorting).first?.startDate
return self.matches().sorted(by: \.computedStartDateForSorting).first?.startDate
}
public override func deleteDependencies(store: Store, actionOption: ActionOption) {

@ -414,8 +414,9 @@ struct SyncDataAccessTests {
eventB.club = club2B.id
try await eventColB.addOrUpdateAsync(instance: eventB)
let _ = try await self.storeCenterA.testSynchronizeOnceAsync()
let data = try await self.storeCenterA.testSynchronizeOnceAsync()
let syncData = try SyncData(data: data, storeCenter: self.storeCenterB)
#expect(eventA.club == club2B.id)
#expect(clubColB.count == 1)
#expect(courtsColB.count == 0)

Loading…
Cancel
Save