sync2
Laurent 10 months ago
parent 9271cee545
commit 37660a1f12
  1. 2
      PadelClub/Data/DataStore.swift
  2. 4
      PadelClub/Data/TournamentLibrary.swift
  3. 14
      PadelClub/Data/TournamentStore.swift
  4. 19
      PadelClub/Views/Navigation/Toolbox/DebugSettingsView.swift
  5. 8
      PadelClub/Views/Tournament/Shared/TournamentCellView.swift

@ -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()

@ -24,4 +24,8 @@ class TournamentLibrary {
return tournamentStore
}
func reset() {
self._stores.removeAll()
}
}

@ -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)
}
}

@ -11,6 +11,14 @@ import LeStorage
struct DebugSettingsView: View {
var body: some View {
List {
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)
@ -19,6 +27,7 @@ struct DebugSettingsView: View {
LabeledContent("CollectionsCanSynchronize", value: self._canSynchronize)
}
}
}
fileprivate var _userId: String {
return StoreCenter.main.userId ?? ""
@ -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 {

@ -42,13 +42,13 @@ struct TournamentCellView: View {
}
var teamCount: Int? {
if let tournament = tournament as? Tournament {
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
} else {
return nil
}
}
fileprivate func _spacing() -> CGFloat {

Loading…
Cancel
Save