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.
 
 
PadelClubData/PadelClubData/Data/TournamentStore.swift

69 lines
2.6 KiB

//
// TournamentStore.swift
// PadelClub
//
// Created by Laurent Morvillier on 26/06/2024.
//
import Foundation
import LeStorage
import SwiftUI
import Combine
public class TournamentStore: ObservableObject {
var store: Store
public fileprivate(set) var groupStages: SyncedCollection<GroupStage> = SyncedCollection.placeholder()
public fileprivate(set) var matches: SyncedCollection<Match> = SyncedCollection.placeholder()
public fileprivate(set) var teamRegistrations: SyncedCollection<TeamRegistration> = SyncedCollection.placeholder()
public fileprivate(set) var playerRegistrations: SyncedCollection<PlayerRegistration> = SyncedCollection.placeholder()
public fileprivate(set) var rounds: SyncedCollection<Round> = SyncedCollection.placeholder()
public fileprivate(set) var teamScores: SyncedCollection<TeamScore> = SyncedCollection.placeholder()
public fileprivate(set) var matchSchedulers: StoredCollection<MatchScheduler> = StoredCollection.placeholder()
public fileprivate(set) var drawLogs: SyncedCollection<DrawLog> = SyncedCollection.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() {
let indexed: Bool = true
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.registerSynchronizedCollection(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)
}
}