You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
2.7 KiB
75 lines
2.7 KiB
//
|
|
// TournamentStore.swift
|
|
// PadelClub
|
|
//
|
|
// Created by Laurent Morvillier on 26/06/2024.
|
|
//
|
|
|
|
import Foundation
|
|
import LeStorage
|
|
import SwiftUI
|
|
|
|
class TournamentStore: ObservableObject {
|
|
|
|
var store: Store
|
|
|
|
fileprivate(set) var groupStages: StoredCollection<GroupStage> = StoredCollection.placeholder()
|
|
fileprivate(set) var matches: StoredCollection<Match> = StoredCollection.placeholder()
|
|
fileprivate(set) var teamRegistrations: StoredCollection<TeamRegistration> = StoredCollection.placeholder()
|
|
fileprivate(set) var playerRegistrations: StoredCollection<PlayerRegistration> = StoredCollection.placeholder()
|
|
fileprivate(set) var rounds: StoredCollection<Round> = StoredCollection.placeholder()
|
|
fileprivate(set) var teamScores: StoredCollection<TeamScore> = StoredCollection.placeholder()
|
|
|
|
fileprivate(set) var matchSchedulers: StoredCollection<MatchScheduler> = StoredCollection.placeholder()
|
|
fileprivate(set) var drawLogs: StoredCollection<DrawLog> = StoredCollection.placeholder()
|
|
|
|
// convenience init(tournament: Tournament) {
|
|
// let store = StoreCenter.main.store(identifier: tournament.id)
|
|
// self.init(store: store)
|
|
// self._initialize()
|
|
// }
|
|
|
|
init(store: Store) {
|
|
self.store = store
|
|
self._initialize()
|
|
}
|
|
|
|
fileprivate func _initialize() {
|
|
|
|
var synchronized: Bool = true
|
|
let indexed: Bool = true
|
|
|
|
#if DEBUG
|
|
if let sync = PListReader.readBool(plist: "local", key: "synchronized") {
|
|
synchronized = sync
|
|
}
|
|
#endif
|
|
|
|
self.groupStages = self.store.registerSynchronizedCollection(indexed: indexed)
|
|
self.rounds = self.store.registerSynchronizedCollection(indexed: indexed)
|
|
self.teamRegistrations = self.store.registerSynchronizedCollection(indexed: indexed)
|
|
self.playerRegistrations = self.store.registerSynchronizedCollection(indexed: indexed)
|
|
self.matches = self.store.registerSynchronizedCollection(indexed: indexed)
|
|
self.teamScores = self.store.registerSynchronizedCollection(indexed: indexed)
|
|
self.matchSchedulers = self.store.registerCollection(indexed: indexed)
|
|
self.drawLogs = self.store.registerCollection(indexed: indexed)
|
|
|
|
self.store.loadCollectionsFromServerIfNoFile()
|
|
|
|
NotificationCenter.default.addObserver(
|
|
self,
|
|
selector: #selector(_leStorageDidSynchronize),
|
|
name: NSNotification.Name.LeStorageDidSynchronize,
|
|
object: nil)
|
|
|
|
}
|
|
|
|
@objc func _leStorageDidSynchronize(notification: Notification) {
|
|
// Logger.log("SYNCED > teamRegistrations count = \(self.teamRegistrations.count)")
|
|
}
|
|
|
|
deinit {
|
|
NotificationCenter.default.removeObserver(self)
|
|
}
|
|
|
|
}
|
|
|