From 6dfa2c82369ae2d844ba96b4323c645a4341fc79 Mon Sep 17 00:00:00 2001 From: Laurent Date: Sat, 20 Jul 2024 11:33:18 +0200 Subject: [PATCH] Fix issue with tournamentStore loading after disconnect --- PadelClub/Data/DataStore.swift | 13 ++++++------- PadelClub/Data/Tournament.swift | 2 +- PadelClub/Views/Calling/CallSettingsView.swift | 2 +- PadelClub/Views/Club/ClubsView.swift | 2 +- .../Views/GroupStage/GroupStagesSettingsView.swift | 2 +- .../Views/Navigation/Agenda/EventListView.swift | 2 +- .../Views/Navigation/Ongoing/OngoingView.swift | 2 +- .../Views/Navigation/Toolbox/ToolboxView.swift | 2 +- PadelClub/Views/Navigation/Umpire/UmpireView.swift | 2 +- PadelClub/Views/Round/RoundView.swift | 2 +- .../Screen/Components/TournamentStatusView.swift | 2 +- PadelClub/Views/Tournament/Subscription/Guard.swift | 2 +- .../Views/Tournament/Subscription/StoreItem.swift | 2 +- .../Views/Tournament/TournamentBuildView.swift | 2 +- PadelClub/Views/Tournament/TournamentView.swift | 2 +- PadelClub/Views/User/LoginView.swift | 2 +- 16 files changed, 21 insertions(+), 22 deletions(-) diff --git a/PadelClub/Data/DataStore.swift b/PadelClub/Data/DataStore.swift index 98eb67a..c4a85fa 100644 --- a/PadelClub/Data/DataStore.swift +++ b/PadelClub/Data/DataStore.swift @@ -54,7 +54,7 @@ class DataStore: ObservableObject { let serverURL: String = URLs.api.rawValue StoreCenter.main.blackListUserName("apple-test") - #if _DEBUG_OPTIONS + #if DEBUG if let server = PListReader.readString(plist: "local", key: "server") { StoreCenter.main.synchronizationApiURL = server } else { @@ -70,7 +70,7 @@ class DataStore: ObservableObject { _ = Guard.main // init - #if _DEBUG_OPTIONS + #if DEBUG if let sync = PListReader.readBool(plist: "local", key: "synchronized") { synchronized = sync } @@ -172,14 +172,9 @@ class DataStore: ObservableObject { } } - StoreCenter.main.disconnect() StoreCenter.main.collectionsCanSynchronize = false - for tournament in self.tournaments { - StoreCenter.main.destroyStore(identifier: tournament.id) - } - self.tournaments.reset() self.clubs.reset() self.courts.reset() @@ -187,6 +182,10 @@ class DataStore: ObservableObject { self.dateIntervals.reset() self.userStorage.reset() + for tournament in self.tournaments { + StoreCenter.main.destroyStore(identifier: tournament.id) + } + Guard.main.disconnect() self.user = self._temporaryLocalUser.item ?? User.placeHolder() diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index 5c812d4..13dc786 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -508,7 +508,7 @@ final class Tournament : ModelObject, Storable { } func courtUsed() -> [Int] { -#if _DEBUG_OPTIONS //DEBUGING TIME +#if DEBUG //DEBUGING TIME let start = Date() defer { let duration = Duration.milliseconds(Date().timeIntervalSince(start) * 1_000) diff --git a/PadelClub/Views/Calling/CallSettingsView.swift b/PadelClub/Views/Calling/CallSettingsView.swift index 04d0fad..7834e0e 100644 --- a/PadelClub/Views/Calling/CallSettingsView.swift +++ b/PadelClub/Views/Calling/CallSettingsView.swift @@ -56,7 +56,7 @@ struct CallSettingsView: View { } } - // #if _DEBUG_OPTIONS + // #if DEBUG Section { RowButtonView("Retirer toutes les convocations", role: .destructive) { let teams = tournament.unsortedTeams() diff --git a/PadelClub/Views/Club/ClubsView.swift b/PadelClub/Views/Club/ClubsView.swift index 5210993..b5ea93e 100644 --- a/PadelClub/Views/Club/ClubsView.swift +++ b/PadelClub/Views/Club/ClubsView.swift @@ -27,7 +27,7 @@ struct ClubsView: View { var body: some View { List { - #if _DEBUG_OPTIONS + #if DEBUG Section { RowButtonView("Delete unexisted clubs", action: { let ids = dataStore.user.clubs diff --git a/PadelClub/Views/GroupStage/GroupStagesSettingsView.swift b/PadelClub/Views/GroupStage/GroupStagesSettingsView.swift index 51739af..8b3770c 100644 --- a/PadelClub/Views/GroupStage/GroupStagesSettingsView.swift +++ b/PadelClub/Views/GroupStage/GroupStagesSettingsView.swift @@ -73,7 +73,7 @@ struct GroupStagesSettingsView: View { } } - #if _DEBUG_OPTIONS + #if DEBUG Section { RowButtonView("delete all group stages") { tournament.deleteGroupStages() diff --git a/PadelClub/Views/Navigation/Agenda/EventListView.swift b/PadelClub/Views/Navigation/Agenda/EventListView.swift index f6ef613..4c89482 100644 --- a/PadelClub/Views/Navigation/Agenda/EventListView.swift +++ b/PadelClub/Views/Navigation/Agenda/EventListView.swift @@ -112,7 +112,7 @@ struct EventListView: View { } } } - #if _DEBUG_OPTIONS + #if DEBUG .swipeActions(edge: .trailing, allowsFullSwipe: true) { Button(role: .destructive) { do { diff --git a/PadelClub/Views/Navigation/Ongoing/OngoingView.swift b/PadelClub/Views/Navigation/Ongoing/OngoingView.swift index 3fdd8f8..3c41cbb 100644 --- a/PadelClub/Views/Navigation/Ongoing/OngoingView.swift +++ b/PadelClub/Views/Navigation/Ongoing/OngoingView.swift @@ -44,7 +44,7 @@ struct OngoingView: View { } footer: { HStack { Text(tournament.eventLabel()) -#if _DEBUG_OPTIONS +#if DEBUG Spacer() FooterButtonView("copier l'id") { let pasteboard = UIPasteboard.general diff --git a/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift b/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift index 6d0fcbd..7980173 100644 --- a/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift +++ b/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift @@ -49,7 +49,7 @@ struct ToolboxView: View { } - #if _DEBUG_OPTIONS + #if DEBUG Section { NavigationLink("Settings") { diff --git a/PadelClub/Views/Navigation/Umpire/UmpireView.swift b/PadelClub/Views/Navigation/Umpire/UmpireView.swift index f15efde..945d2d7 100644 --- a/PadelClub/Views/Navigation/Umpire/UmpireView.swift +++ b/PadelClub/Views/Navigation/Umpire/UmpireView.swift @@ -145,7 +145,7 @@ struct UmpireView: View { } .navigationTitle("Juge-Arbitre") .toolbar { -#if _DEBUG_OPTIONS +#if DEBUG ToolbarItem(placement: .topBarTrailing) { if StoreCenter.main.collectionsCanSynchronize { Image(systemName: "checkmark.icloud") diff --git a/PadelClub/Views/Round/RoundView.swift b/PadelClub/Views/Round/RoundView.swift index acc50e9..3891599 100644 --- a/PadelClub/Views/Round/RoundView.swift +++ b/PadelClub/Views/Round/RoundView.swift @@ -254,7 +254,7 @@ struct RoundView: View { } } - #if _DEBUG_OPTIONS + #if DEBUG Spacer() Text(match.teamScores.count.formatted()) diff --git a/PadelClub/Views/Tournament/Screen/Components/TournamentStatusView.swift b/PadelClub/Views/Tournament/Screen/Components/TournamentStatusView.swift index 1f66b8f..9add4fd 100644 --- a/PadelClub/Views/Tournament/Screen/Components/TournamentStatusView.swift +++ b/PadelClub/Views/Tournament/Screen/Components/TournamentStatusView.swift @@ -17,7 +17,7 @@ struct TournamentStatusView: View { var body: some View { Form { - #if _DEBUG_OPTIONS + #if DEBUG RowButtonView("debug: Un-delete le tournoi") { tournament.endDate = nil tournament.isDeleted.toggle() diff --git a/PadelClub/Views/Tournament/Subscription/Guard.swift b/PadelClub/Views/Tournament/Subscription/Guard.swift index bffa090..36c77cd 100644 --- a/PadelClub/Views/Tournament/Subscription/Guard.swift +++ b/PadelClub/Views/Tournament/Subscription/Guard.swift @@ -141,7 +141,7 @@ import LeStorage var currentPlan: StoreItem? { return .monthlyUnlimited -// #if _DEBUG_OPTIONS +// #if DEBUG // return .monthlyUnlimited // #else if let currentBestPlan = self.currentBestPlan, let plan = StoreItem(rawValue: currentBestPlan.productID) { diff --git a/PadelClub/Views/Tournament/Subscription/StoreItem.swift b/PadelClub/Views/Tournament/Subscription/StoreItem.swift index 8a2e71e..79bab93 100644 --- a/PadelClub/Views/Tournament/Subscription/StoreItem.swift +++ b/PadelClub/Views/Tournament/Subscription/StoreItem.swift @@ -12,7 +12,7 @@ enum StoreItem: String, Identifiable, CaseIterable { case fivePerMonth = "app.padelclub.tournament.subscription.five.per.month" case unit = "app.padelclub.tournament.unit" - #if _DEBUG_OPTIONS + #if DEBUG static let five: Int = 2 #else static let five: Int = 5 diff --git a/PadelClub/Views/Tournament/TournamentBuildView.swift b/PadelClub/Views/Tournament/TournamentBuildView.swift index 75e5b36..a11e055 100644 --- a/PadelClub/Views/Tournament/TournamentBuildView.swift +++ b/PadelClub/Views/Tournament/TournamentBuildView.swift @@ -92,7 +92,7 @@ struct TournamentBuildView: View { Section { - #if _DEBUG_OPTIONS + #if DEBUG NavigationLink(value: Screen.rankings) { LabeledContent { if tournament.publishRankings == false { diff --git a/PadelClub/Views/Tournament/TournamentView.swift b/PadelClub/Views/Tournament/TournamentView.swift index 6f3f946..fa14f46 100644 --- a/PadelClub/Views/Tournament/TournamentView.swift +++ b/PadelClub/Views/Tournament/TournamentView.swift @@ -154,7 +154,7 @@ struct TournamentView: View { ToolbarItem(placement: .topBarTrailing) { Menu { - #if _DEBUG_OPTIONS + #if DEBUG Button { do { try self.tournament.payIfNecessary() diff --git a/PadelClub/Views/User/LoginView.swift b/PadelClub/Views/User/LoginView.swift index 31e99e0..0e0b75f 100644 --- a/PadelClub/Views/User/LoginView.swift +++ b/PadelClub/Views/User/LoginView.swift @@ -180,7 +180,7 @@ struct LoginView: View { } .navigationTitle("Connexion") .onAppear { - #if _DEBUG_OPTIONS + #if DEBUG if let username = PListReader.readString(plist: "local", key: "username") { self.username = username }