Skip to content

Commit

Permalink
Fix subscriptions glitch in Settings (#2828)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/414235014887631/1207214261396124/f

Description:
Caches subscription availability state in the view, so is not refreshed on view rendering.
  • Loading branch information
afterxleep authored May 6, 2024
1 parent 1ae5c1b commit b1aa99e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "46989693916f56d1186bd59ac15124caef896560",
"version" : "1.3.1"
Expand Down
81 changes: 44 additions & 37 deletions DuckDuckGo/SettingsSubscriptionView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct SettingsSubscriptionView: View {
@State var isShowingGoogleView = false
@State var isShowingStripeView = false
@State var isShowingSubscriptionError = false
@State var isShowingPrivacyPro = false

enum Constants {
static let purchaseDescriptionPadding = 5.0
Expand Down Expand Up @@ -205,47 +206,53 @@ struct SettingsSubscriptionView: View {
}

var body: some View {
if viewModel.state.subscription.enabled && viewModel.state.subscription.canPurchase {

Section(header: Text(UserText.settingsPProSection)) {

switch (
viewModel.state.subscription.isSignedIn,
viewModel.state.subscription.hasActiveSubscription,
viewModel.state.subscription.entitlements.isEmpty
) {

// Signed In, Subscription Expired
case (true, false, _):
subscriptionExpiredView

// Signed in, Subscription Active, Valid entitlements
case (true, true, false):
subscriptionDetailsView // View for valid subscription details

// Signed in, Subscription Active, Empty Entitlements
case (true, true, true):
noEntitlementsAvailableView // View for no entitlements

// Signed out
case (false, _, _):
purchaseSubscriptionView // View for signing up or purchasing a subscription
Group {
if isShowingPrivacyPro {

Section(header: Text(UserText.settingsPProSection)) {

switch (
viewModel.state.subscription.isSignedIn,
viewModel.state.subscription.hasActiveSubscription,
viewModel.state.subscription.entitlements.isEmpty
) {

// Signed In, Subscription Expired
case (true, false, _):
subscriptionExpiredView

// Signed in, Subscription Active, Valid entitlements
case (true, true, false):
subscriptionDetailsView // View for valid subscription details

// Signed in, Subscription Active, Empty Entitlements
case (true, true, true):
noEntitlementsAvailableView // View for no entitlements

// Signed out
case (false, _, _):
purchaseSubscriptionView // View for signing up or purchasing a subscription
}
}
}

.onChange(of: viewModel.state.subscription.shouldDisplayRestoreSubscriptionError) { value in
if value {
isShowingSubscriptionError = true
.onChange(of: viewModel.state.subscription.shouldDisplayRestoreSubscriptionError) { value in
if value {
isShowingSubscriptionError = true
}
}
}

.onReceive(subscriptionNavigationCoordinator.$shouldPopToAppSettings) { shouldDismiss in
if shouldDismiss {
isShowingRestoreFlow = false
isShowingSubscribeFlow = false
.onReceive(subscriptionNavigationCoordinator.$shouldPopToAppSettings) { shouldDismiss in
if shouldDismiss {
isShowingRestoreFlow = false
isShowingSubscribeFlow = false
}
}

}
}.onReceive(viewModel.$state) { state in
if state.subscription.enabled && state.subscription.canPurchase {
isShowingPrivacyPro = true
}

}
}
}

0 comments on commit b1aa99e

Please sign in to comment.