From 7811806925e8400ab8c6a32f195839d2070b17cc Mon Sep 17 00:00:00 2001 From: Laurent Date: Thu, 17 Oct 2024 10:10:07 +0200 Subject: [PATCH] Make server purchase active --- PadelClub/Data/DataStore.swift | 4 ++++ PadelClub/Views/Tournament/Subscription/Guard.swift | 11 ++++++++++- PadelClub/Views/User/AccountView.swift | 5 +++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/PadelClub/Data/DataStore.swift b/PadelClub/Data/DataStore.swift index 2a2052e..4ebdaad 100644 --- a/PadelClub/Data/DataStore.swift +++ b/PadelClub/Data/DataStore.swift @@ -101,6 +101,10 @@ class DataStore: ObservableObject { } + deinit { + NotificationCenter.default.removeObserver(self) + } + func saveUser() { do { if user.username.count > 0 { diff --git a/PadelClub/Views/Tournament/Subscription/Guard.swift b/PadelClub/Views/Tournament/Subscription/Guard.swift index 64cbdac..e2a03ec 100644 --- a/PadelClub/Views/Tournament/Subscription/Guard.swift +++ b/PadelClub/Views/Tournament/Subscription/Guard.swift @@ -19,7 +19,6 @@ import LeStorage var currentBestPurchase: Purchase? = nil var updateListenerTask: Task? = nil - override init() { @@ -34,10 +33,20 @@ import LeStorage Logger.error(error) } } + + NotificationCenter.default.addObserver(self, selector: #selector(collectionDidLoad), name: NSNotification.Name.CollectionDidLoad, object: nil) + } deinit { self.updateListenerTask?.cancel() + NotificationCenter.default.removeObserver(self) + } + + @objc func collectionDidLoad(notification: Notification) { + if let _ = notification.object as? StoredCollection { + self._updateBestPlan() + } } func productIds() async -> [String] { diff --git a/PadelClub/Views/User/AccountView.swift b/PadelClub/Views/User/AccountView.swift index a45da3e..340e162 100644 --- a/PadelClub/Views/User/AccountView.swift +++ b/PadelClub/Views/User/AccountView.swift @@ -15,6 +15,11 @@ struct AccountView: View { var body: some View { Form { + #if DEBUG + if let purchase = Guard.main.currentBestPurchase, let item = StoreItem(rawValue: purchase.productId) { + PurchaseView(purchaseRow: PurchaseRow(id: purchase.id, name: purchase.productId, item: item)) + } + #endif Section { NavigationLink("Changer de mot de passe") { ChangePasswordView()