Fixes and improvements

multistore
Laurent 1 year ago
parent 00a1ccf5f5
commit c2ad10e297
  1. 37
      PadelClub/Data/DataStore.swift
  2. 7
      PadelClub/Data/TournamentStore.swift
  3. 6
      PadelClub/Views/Tournament/Shared/TournamentCellView.swift

@ -15,7 +15,7 @@ class DataStore: ObservableObject {
@Published var user: User = User.placeHolder() {
didSet {
let loggedUser = (user.username.count > 0)
let loggedUser = StoreCenter.main.userId != nil
StoreCenter.main.collectionsCanSynchronize = loggedUser
if loggedUser {
@ -37,15 +37,8 @@ class DataStore: ObservableObject {
fileprivate(set) var clubs: StoredCollection<Club>
fileprivate(set) var courts: StoredCollection<Court>
fileprivate(set) var events: StoredCollection<Event>
// fileprivate(set) var groupStages: StoredCollection<GroupStage>
// fileprivate(set) var matches: StoredCollection<Match>
// fileprivate(set) var teamRegistrations: StoredCollection<TeamRegistration>
// fileprivate(set) var playerRegistrations: StoredCollection<PlayerRegistration>
// fileprivate(set) var rounds: StoredCollection<Round>
// fileprivate(set) var teamScores: StoredCollection<TeamScore>
fileprivate(set) var monthData: StoredCollection<MonthData>
fileprivate(set) var dateIntervals: StoredCollection<DateInterval>
// fileprivate(set) var matchSchedulers: StoredCollection<MatchScheduler>
fileprivate var userStorage: StoredSingleton<User>
@ -90,15 +83,8 @@ class DataStore: ObservableObject {
self.courts = store.registerCollection(synchronized: synchronized, indexed: indexed)
self.tournaments = store.registerCollection(synchronized: synchronized, indexed: indexed)
self.events = store.registerCollection(synchronized: synchronized, indexed: indexed)
// self.groupStages = store.registerCollection(synchronized: synchronized, indexed: indexed)
// self.teamScores = store.registerCollection(synchronized: synchronized, indexed: indexed)
// self.teamRegistrations = store.registerCollection(synchronized: synchronized, indexed: indexed)
// self.playerRegistrations = store.registerCollection(synchronized: synchronized, indexed: indexed)
// self.rounds = store.registerCollection(synchronized: synchronized, indexed: indexed)
// self.matches = store.registerCollection(synchronized: synchronized, indexed: indexed)
self.monthData = store.registerCollection(synchronized: false, indexed: indexed)
self.dateIntervals = store.registerCollection(synchronized: synchronized, indexed: indexed)
// self.matchSchedulers = store.registerCollection(synchronized: false, indexed: indexed)
self.userStorage = store.registerObject(synchronized: synchronized)
@ -131,10 +117,7 @@ class DataStore: ObservableObject {
self._fixMissingClubCreatorIfNecessary(clubsCollection)
} else if let eventsCollection: StoredCollection<Event> = notification.object as? StoredCollection<Event> {
self._fixMissingEventCreatorIfNecessary(eventsCollection)
}
// else if let purchaseCollection: StoredCollection<Purchase> = notification.object as? StoredCollection<Purchase> {
// try? purchaseCollection.deleteAll()
// }
}
}
fileprivate func _fixMissingClubCreatorIfNecessary(_ clubsCollection: StoredCollection<Club>) {
@ -172,9 +155,6 @@ class DataStore: ObservableObject {
}
}
self.user = self._temporaryLocalUser.item ?? User.placeHolder()
self.user.clubs.removeAll()
StoreCenter.main.disconnect()
StoreCenter.main.collectionsCanSynchronize = false
@ -186,18 +166,13 @@ class DataStore: ObservableObject {
self.clubs.reset()
self.courts.reset()
self.events.reset()
// self.groupStages.reset()
// self.matches.reset()
// self.teamRegistrations.reset()
// self.playerRegistrations.reset()
// self.rounds.reset()
// self.teamScores.reset()
self.dateIntervals.reset()
// self.matchSchedulers.reset()
self.userStorage.reset()
Guard.main.disconnect()
self.user = self._temporaryLocalUser.item ?? User.placeHolder()
self.user.clubs.removeAll()
}
@ -264,8 +239,6 @@ class DataStore: ObservableObject {
// MARK: - Convenience
func runningMatches() -> [Match] {
// let tournaments: [Tournament] = self.tournaments // foutu
let lastTournaments = self.tournaments.sorted(by: \Tournament.startDate).prefix(10)
var runningMatches: [Match] = []

@ -12,6 +12,9 @@ import SwiftUI
class TournamentStore: Store, ObservableObject {
static func instance(tournamentId: String) -> TournamentStore {
// if StoreCenter.main.userId == nil {
// fatalError("cant request store without id")
// }
return StoreCenter.main.store(identifier: tournamentId, parameter: "tournament")
}
@ -24,8 +27,6 @@ class TournamentStore: Store, ObservableObject {
fileprivate(set) var matchSchedulers: StoredCollection<MatchScheduler> = StoredCollection.placeholder()
// fileprivate(set) var loading: Bool = true
convenience init(tournament: Tournament) {
self.init(identifier: tournament.id, parameter: "tournament")
}
@ -51,6 +52,8 @@ class TournamentStore: Store, ObservableObject {
self.teamScores = self.registerCollection(synchronized: synchronized, indexed: indexed)
self.matchSchedulers = self.registerCollection(synchronized: false, indexed: indexed)
self.loadCollectionsFromServerIfNoFile()
}
}

@ -22,8 +22,10 @@ struct TournamentCellView: View {
}
var body: some View {
ForEach(tournament.tournaments, id: \.id) { build in
_buildView(build, existingTournament: event?.existingBuild(build))
if dataStore.tournaments.count > 0 {
ForEach(tournament.tournaments, id: \.id) { build in
_buildView(build, existingTournament: event?.existingBuild(build))
}
}
}

Loading…
Cancel
Save