Skip to content

Commit

Permalink
disable all buttons if loading
Browse files Browse the repository at this point in the history
  • Loading branch information
vegaro committed Jul 18, 2024
1 parent 0057dda commit f462b7f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class FeedbackSurveyViewModel: ObservableObject {
var feedbackSurveyData: FeedbackSurveyData

@Published
var loadingStates: [String: Bool] = [:]
var loadingState: String?
@Published
var promotionalOfferData: PromotionalOfferData?

Expand Down Expand Up @@ -57,7 +57,7 @@ class FeedbackSurveyViewModel: ObservableObject {

func handleAction(for option: CustomerCenterConfigData.HelpPath.FeedbackSurvey.Option) async {
if let promotionalOffer = option.promotionalOffer {
self.loadingStates[option.id] = true
self.loadingState = option.id
let result = await loadPromotionalOfferUseCase.execute(promoOfferDetails: promotionalOffer)
switch result {
case .success(let promotionalOfferData):
Expand All @@ -72,7 +72,7 @@ class FeedbackSurveyViewModel: ObservableObject {

func handleSheetDismiss() {
self.feedbackSurveyData.action()
self.loadingStates.removeAll()
self.loadingState = nil
}

}
Expand Down
8 changes: 4 additions & 4 deletions RevenueCatUI/CustomerCenter/Views/FeedbackSurveyView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct FeedbackSurveyView: View {

FeedbackSurveyButtonsView(options: self.viewModel.feedbackSurveyData.configuration.options,
onOptionSelected: self.viewModel.handleAction(for:),
loadingStates: self.$viewModel.loadingStates)
loadingState: self.$viewModel.loadingState)
}
.sheet(
item: self.$viewModel.promotionalOfferData,
Expand All @@ -68,22 +68,22 @@ struct FeedbackSurveyButtonsView: View {
let options: [CustomerCenterConfigData.HelpPath.FeedbackSurvey.Option]
let onOptionSelected: (_ optionSelected: CustomerCenterConfigData.HelpPath.FeedbackSurvey.Option) async -> Void
@Binding
var loadingStates: [String: Bool]
var loadingState: String?

var body: some View {
VStack(spacing: Self.buttonSpacing) {
ForEach(options, id: \.id) { option in
AsyncButton(action: {
await self.onOptionSelected(option)
}, label: {
if self.loadingStates[option.id] ?? false {
if self.loadingState == option.id {
ProgressView()
} else {
Text(option.title)
}
})
.buttonStyle(ManageSubscriptionsButtonStyle())
.disabled(self.loadingStates[option.id] ?? false)
.disabled(self.loadingState != nil)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ struct ManageSubscriptionButton: View {
localization: self.viewModel.localization)
})
.buttonStyle(ManageSubscriptionsButtonStyle())
.disabled(self.viewModel.loadingPath?.id == path.id)
.disabled(self.viewModel.loadingPath != nil)
}
}

Expand Down

0 comments on commit f462b7f

Please sign in to comment.