diff --git a/PadelClub/Data/DataStore.swift b/PadelClub/Data/DataStore.swift index 1c1942d..6d59761 100644 --- a/PadelClub/Data/DataStore.swift +++ b/PadelClub/Data/DataStore.swift @@ -102,7 +102,7 @@ class DataStore: ObservableObject { NotificationCenter.default.addObserver(self, selector: #selector(collectionDidLoad), name: NSNotification.Name.CollectionDidLoad, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(collectionDidUpdate), name: NSNotification.Name.CollectionDidChange, object: nil) - + } deinit { @@ -210,6 +210,8 @@ class DataStore: ObservableObject { let tournamendIds: [String] = self.tournaments.map { $0.id } + TournamentLibrary.shared.reset() + self.tournaments.reset() self.clubs.reset() self.courts.reset() diff --git a/PadelClub/Data/TournamentLibrary.swift b/PadelClub/Data/TournamentLibrary.swift index 948a65e..228e6e2 100644 --- a/PadelClub/Data/TournamentLibrary.swift +++ b/PadelClub/Data/TournamentLibrary.swift @@ -24,4 +24,8 @@ class TournamentLibrary { return tournamentStore } + func reset() { + self._stores.removeAll() + } + } diff --git a/PadelClub/Data/TournamentStore.swift b/PadelClub/Data/TournamentStore.swift index bdc5bb9..5439e30 100644 --- a/PadelClub/Data/TournamentStore.swift +++ b/PadelClub/Data/TournamentStore.swift @@ -56,6 +56,20 @@ class TournamentStore: ObservableObject { self.store.loadCollectionsFromServerIfNoFile() + NotificationCenter.default.addObserver( + self, + selector: #selector(_leStorageDidSynchronize), + name: NSNotification.Name.LeStorageDidSynchronize, + object: nil) + + } + + @objc func _leStorageDidSynchronize(notification: Notification) { + Logger.log("SYNCED > Match count = \(self.matches.count)") + } + + deinit { + NotificationCenter.default.removeObserver(self) } } diff --git a/PadelClub/Views/Navigation/Toolbox/DebugSettingsView.swift b/PadelClub/Views/Navigation/Toolbox/DebugSettingsView.swift index f2f7943..246c3a7 100644 --- a/PadelClub/Views/Navigation/Toolbox/DebugSettingsView.swift +++ b/PadelClub/Views/Navigation/Toolbox/DebugSettingsView.swift @@ -11,12 +11,21 @@ import LeStorage struct DebugSettingsView: View { var body: some View { List { - LabeledContent("UUID", value: self._userId) - LabeledContent("User Name", value: self._userName) - LabeledContent("Token", value: self._token) - LabeledContent("Server", value: self._apiURL) - LabeledContent("Synchronized", value: self._synchronized) - LabeledContent("CollectionsCanSynchronize", value: self._canSynchronize) + + Section("Status") { + LabeledContent("Has Websocket Manager", value: self._hasWebSocketManager) + LabeledContent("Websocket ping", value: self._wsPingStatus) + LabeledContent("Websocket failure", value: self._wsFailure) + } + + Section("Settings") { + LabeledContent("UUID", value: self._userId) + LabeledContent("User Name", value: self._userName) + LabeledContent("Token", value: self._token) + LabeledContent("Server", value: self._apiURL) + LabeledContent("Synchronized", value: self._synchronized) + LabeledContent("CollectionsCanSynchronize", value: self._canSynchronize) + } } } @@ -47,6 +56,16 @@ struct DebugSettingsView: View { fileprivate var _canSynchronize: String { return "\(StoreCenter.main.collectionsCanSynchronize)" } + + fileprivate var _wsPingStatus: String { + return "\(StoreCenter.main.websocketPingStatus)" + } + fileprivate var _wsFailure: String { + return "\(StoreCenter.main.websocketFailure)" + } + fileprivate var _hasWebSocketManager: String { + return "\(StoreCenter.main.hasWebSocketManager)" + } } //#Preview { diff --git a/PadelClub/Views/Tournament/Shared/TournamentCellView.swift b/PadelClub/Views/Tournament/Shared/TournamentCellView.swift index e3b862d..dd7169c 100644 --- a/PadelClub/Views/Tournament/Shared/TournamentCellView.swift +++ b/PadelClub/Views/Tournament/Shared/TournamentCellView.swift @@ -42,13 +42,13 @@ struct TournamentCellView: View { } var teamCount: Int? { - if let tournament = tournament as? Tournament { - let hasStarted = tournament.inscriptionClosed() || tournament.hasStarted() - let count = hasStarted ? tournament.selectedSortedTeams().count : tournament.unsortedTeamsWithoutWO().count - return count - } else { + guard let tournament = tournament as? Tournament, DataStore.shared.tournaments.contains(where: {$0.id == self.tournament.holderId }) else { // we make sure the tournament is in the DataStore otherwise we keep instantiating TournamentStore after disconnections return nil } + + let hasStarted = tournament.inscriptionClosed() || tournament.hasStarted() + let count = hasStarted ? tournament.selectedSortedTeams().count : tournament.unsortedTeamsWithoutWO().count + return count } fileprivate func _spacing() -> CGFloat {