multistore
Laurent 1 year ago
parent cc4563b663
commit fb3fe585b9
  1. 5
      PadelClub/Data/DataStore.swift
  2. 4
      PadelClub/Views/Navigation/Toolbox/APICallsListView.swift
  3. 13
      PadelClub/Views/Navigation/Toolbox/ToolboxView.swift
  4. 11
      PadelClub/Views/Navigation/Umpire/UmpireView.swift
  5. 15
      PadelClub/Views/Subscription/Guard.swift
  6. 28
      PadelClub/Views/Subscription/PurchaseListView.swift
  7. 16
      PadelClub/Views/Subscription/SubscriptionView.swift
  8. 7
      PadelClub/Views/User/LoginView.swift

@ -120,9 +120,10 @@ class DataStore: ObservableObject {
self._fixMissingClubCreatorIfNecessary(clubsCollection)
} else if let eventsCollection: StoredCollection<Event> = notification.object as? StoredCollection<Event> {
self._fixMissingEventCreatorIfNecessary(eventsCollection)
} else if let purchaseCollection: StoredCollection<Purchase> = notification.object as? StoredCollection<Purchase> {
try? purchaseCollection.deleteAll()
}
// else if let purchaseCollection: StoredCollection<Purchase> = notification.object as? StoredCollection<Purchase> {
// try? purchaseCollection.deleteAll()
// }
}
fileprivate func _fixMissingClubCreatorIfNecessary(_ clubsCollection: StoredCollection<Club>) {

@ -32,7 +32,9 @@ struct APICallsView: View {
var text: String
var body: some View {
Text(self.text)
List {
Text(self.text).lineLimit(nil)
}
}
}

@ -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 {

@ -37,6 +37,7 @@ struct UmpireView: View {
PurchaseListView()
if Guard.main.currentPlan != .monthlyUnlimited {
Section {
Button {
self.showSubscriptions = true
@ -44,15 +45,7 @@ struct UmpireView: View {
Label("Les offres", systemImage: "bookmark.fill")
}
}
// Section {
// NavigationLink {
// SubscriptionView()
// } label: {
// Label("Les offres", systemImage: "bookmark.fill")
// }
// }
}
NavigationLink {
MainUserView()

@ -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] {

@ -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<Purchase> 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 {

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

@ -45,7 +45,11 @@ struct LoginView: View {
self._login()
}, label: {
if self.isLoading {
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

Loading…
Cancel
Save