diff --git a/PadelClub/Data/DataStore.swift b/PadelClub/Data/DataStore.swift index 996c619..a101ad4 100644 --- a/PadelClub/Data/DataStore.swift +++ b/PadelClub/Data/DataStore.swift @@ -120,9 +120,10 @@ class DataStore: ObservableObject { self._fixMissingClubCreatorIfNecessary(clubsCollection) } else if let eventsCollection: StoredCollection = notification.object as? StoredCollection { self._fixMissingEventCreatorIfNecessary(eventsCollection) - } else if let purchaseCollection: StoredCollection = notification.object as? StoredCollection { - try? purchaseCollection.deleteAll() - } + } +// else if let purchaseCollection: StoredCollection = notification.object as? StoredCollection { +// try? purchaseCollection.deleteAll() +// } } fileprivate func _fixMissingClubCreatorIfNecessary(_ clubsCollection: StoredCollection) { diff --git a/PadelClub/Views/Navigation/Toolbox/APICallsListView.swift b/PadelClub/Views/Navigation/Toolbox/APICallsListView.swift index 0a5c7b4..4700e81 100644 --- a/PadelClub/Views/Navigation/Toolbox/APICallsListView.swift +++ b/PadelClub/Views/Navigation/Toolbox/APICallsListView.swift @@ -32,7 +32,9 @@ struct APICallsView: View { var text: String var body: some View { - Text(self.text) + List { + Text(self.text).lineLimit(nil) + } } } diff --git a/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift b/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift index 541ce97..19985c8 100644 --- a/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift +++ b/PadelClub/Views/Navigation/Toolbox/ToolboxView.swift @@ -29,17 +29,8 @@ struct ToolboxView: View { Section { RowButtonView("Reset ALL API Calls") { - dataStore.courts.resetApiCalls() - dataStore.matches.resetApiCalls() - dataStore.tournaments.resetApiCalls() - dataStore.teamRegistrations.resetApiCalls() - dataStore.playerRegistrations.resetApiCalls() - dataStore.teamScores.resetApiCalls() - dataStore.rounds.resetApiCalls() - dataStore.groupStages.resetApiCalls() - dataStore.clubs.resetApiCalls() - dataStore.events.resetApiCalls() - dataStore.dateIntervals.resetApiCalls() + Store.main.resetApiCalls() + Logger.log("Api calls reset") } } Section { diff --git a/PadelClub/Views/Navigation/Umpire/UmpireView.swift b/PadelClub/Views/Navigation/Umpire/UmpireView.swift index 9638af4..2d19134 100644 --- a/PadelClub/Views/Navigation/Umpire/UmpireView.swift +++ b/PadelClub/Views/Navigation/Umpire/UmpireView.swift @@ -37,23 +37,16 @@ struct UmpireView: View { PurchaseListView() - Section { - Button { - self.showSubscriptions = true - } label: { - Label("Les offres", systemImage: "bookmark.fill") + if Guard.main.currentPlan != .monthlyUnlimited { + Section { + Button { + self.showSubscriptions = true + } label: { + Label("Les offres", systemImage: "bookmark.fill") + } } } - -// Section { -// NavigationLink { -// SubscriptionView() -// } label: { -// Label("Les offres", systemImage: "bookmark.fill") -// } -// } - NavigationLink { MainUserView() } label: { diff --git a/PadelClub/Views/Subscription/Guard.swift b/PadelClub/Views/Subscription/Guard.swift index 5aa7039..c74974e 100644 --- a/PadelClub/Views/Subscription/Guard.swift +++ b/PadelClub/Views/Subscription/Guard.swift @@ -24,7 +24,7 @@ import LeStorage override init() { - self.purchases = Store.main.registerCollection(synchronized: true, inMemory: true, sendsUpdate: false) + self.purchases = Store.main.registerCollection(synchronized: true, inMemory: true) super.init() @@ -94,11 +94,6 @@ import LeStorage purchasedTransactions.insert(transaction) try self._addPurchaseIfPossible(transaction: transaction) - -// if self._purchaseById(transaction.originalID) == nil { -// let purchase: Purchase = transaction.purchase() -// try self.purchases.addOrUpdate(instance: purchase) -// } } else { // If the App Store has revoked this transaction, remove it from the list of `purchasedIdentifiers`. purchasedTransactions.remove(transaction) @@ -145,14 +140,14 @@ import LeStorage } var currentPlan: StoreItem? { - #if DEBUG - return .monthlyUnlimited - #else +// #if DEBUG +// return .monthlyUnlimited +// #else if let currentBestPlan = self.currentBestPlan, let plan = StoreItem(rawValue: currentBestPlan.productID) { return plan } return nil - #endif +// #endif } func userFilteredPurchases() -> [StoreKit.Transaction] { diff --git a/PadelClub/Views/Subscription/PurchaseListView.swift b/PadelClub/Views/Subscription/PurchaseListView.swift index 5a4751a..1420176 100644 --- a/PadelClub/Views/Subscription/PurchaseListView.swift +++ b/PadelClub/Views/Subscription/PurchaseListView.swift @@ -14,12 +14,12 @@ class PurchaseManager: ObservableObject { static let main: PurchaseManager = PurchaseManager() fileprivate var _products: [Product] = [] - fileprivate var _purchases: [Purchase] = [] +// fileprivate var _purchases: [Purchase] = [] @Published var purchaseRows: [PurchaseRow] = [] init() { -// NotificationCenter.default.addObserver(self, selector: #selector(_purchasesChanged(notification:)), name: NSNotification.Name.CollectionDidChange, object: Guard.main.purchases) + NotificationCenter.default.addObserver(self, selector: #selector(_purchasesChanged(notification:)), name: NSNotification.Name.StoreEventHappened, object: nil) let identifiers: [String] = StoreItem.allCases.map { $0.rawValue } @@ -34,11 +34,6 @@ class PurchaseManager: ObservableObject { } @objc fileprivate func _purchasesChanged(notification: Notification) { - guard let collection = notification.object as? StoredCollection else { - return - } - self._purchases.removeAll() - self._purchases.append(contentsOf: collection) self._buildRowsOnMainThread() } @@ -64,21 +59,6 @@ class PurchaseManager: ObservableObject { } } - - // Subscriptions -// for userPurchase in userPurchases { -// print("from = \(userPurchase.purchaseDate) / to = \(userPurchase.expirationDate)") -// if let item = StoreItem(rawValue: userPurchase.productID), -// let product = self._products.first(where: { $0.id == item.rawValue } ) { -// switch item { -// case .fivePerMonth, .monthlyUnlimited: -// rows.append(PurchaseRow(id: userPurchase.originalID, name: product.displayName, item: item)) -// case .unit: -// break -// } -// } -// } - // Units let remainingTournaments = Guard.main.remainingTournaments if remainingTournaments > 0 { @@ -88,6 +68,8 @@ class PurchaseManager: ObservableObject { } } + Logger.log("purchases = \(rows)") + self.purchaseRows = rows } @@ -123,7 +105,7 @@ struct PurchaseView: View { var body: some View { HStack { Image(systemName: self.purchaseRow.item.systemImage) - .foregroundColor(.accentColor) + .foregroundColor(.accentColor).font(.title2) Text(self.purchaseRow.name) Spacer() if let _ = purchaseRow.quantity { diff --git a/PadelClub/Views/Subscription/SubscriptionView.swift b/PadelClub/Views/Subscription/SubscriptionView.swift index 823ad3b..6736a7e 100644 --- a/PadelClub/Views/Subscription/SubscriptionView.swift +++ b/PadelClub/Views/Subscription/SubscriptionView.swift @@ -53,7 +53,7 @@ class SubscriptionModel: ObservableObject, StoreDelegate { @Published var totalPrice: String = "" init() { - Logger.log("SubscriptionModel init ") + self.load() } func load() { @@ -123,9 +123,6 @@ struct SubscriptionView: View { init(isPresented: Binding, showLackOfPlanMessage: Bool = false) { self._isPresented = isPresented self.showLackOfPlanMessage = showLackOfPlanMessage - - Logger.log(">>> SubscriptionView init") - } var body: some View { @@ -174,7 +171,7 @@ struct SubscriptionView: View { Section { Button { - if Store.main.hasToken() { + if Store.main.userId != nil { self._purchase() } else { self.showLoginView = true @@ -241,9 +238,7 @@ struct SubscriptionView: View { } .preferredColorScheme(.dark) .navigationTitle("Abonnements") - .onAppear { - self.model.load() - } + } fileprivate func _purchase() { @@ -301,7 +296,8 @@ struct ProductView: View { Text(product.formattedPrice) .foregroundColor(.accentColor) if self._isConsumable { - StepperView(count: self.$quantity, minimum: 1).font(.callout) + StepperView(count: self.$quantity, minimum: 1) + .font(.callout).foregroundColor(.accentColor) } } Spacer() @@ -374,7 +370,7 @@ struct SubscriptionDetailView: View { Image(systemName: "exclamationmark.bubble.fill") //.foregroundStyle(Color.accentColor) .font(.title) - Text("Vous ne disposez malheureusement plus d'offre pour continuer votre tournoi. Voici ce que nous proposons:") + Text("Vous êtes arrivé à limite de votre offre actuelle. Voici ce que nous proposons pour poursuivre votre tournoi:") .fontWeight(.semibold) } .padding() diff --git a/PadelClub/Views/User/LoginView.swift b/PadelClub/Views/User/LoginView.swift index 97cf04b..199c89b 100644 --- a/PadelClub/Views/User/LoginView.swift +++ b/PadelClub/Views/User/LoginView.swift @@ -45,7 +45,11 @@ struct LoginView: View { self._login() }, label: { if self.isLoading { - ProgressView() + HStack { + Spacer() + ProgressView() + Spacer() + } } else { Text("Connexion").frame(maxWidth: .infinity) } @@ -92,6 +96,7 @@ struct LoginView: View { fileprivate func _login() { self.errorText = nil // reset error + self.isLoading = true Task { do { let service = try Store.main.service() @@ -99,8 +104,10 @@ struct LoginView: View { username: self.username, password: self.password) self.dataStore.user = user + self.isLoading = false self.handler(user) } catch { + self.isLoading = false switch error { case ServiceError.responseError(let reason): self.errorText = reason