Skip to content

Commit

Permalink
check state
Browse files Browse the repository at this point in the history
  • Loading branch information
vegaro committed Dec 11, 2024
1 parent 91c21cb commit e1c7637
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
14 changes: 8 additions & 6 deletions RevenueCatUI/CustomerCenter/Views/CustomerCenterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,19 @@ public struct CustomerCenterView: View {
// swiftlint:disable:next missing_docs
public var body: some View {
Group {
if !self.viewModel.isLoaded {
TintedProgressView()
} else {
switch self.viewModel.state {
case .error:
ErrorView()
case .loaded:
if let configuration = self.viewModel.configuration {
destinationView(configuration: configuration)
.environment(\.localization, configuration.localization)
.environment(\.appearance, configuration.appearance)
.environment(\.supportInformation, configuration.support)
.environment(\.customerCenterPresentationMode, self.mode)
}
default:
TintedProgressView()
}
}
.task {
Expand All @@ -104,9 +107,8 @@ public struct CustomerCenterView: View {
private extension CustomerCenterView {

func loadInformationIfNeeded() async {
if !viewModel.isLoaded {
await viewModel.loadPurchaseInformation()
await viewModel.loadCustomerCenterConfig()
if viewModel.state == .notLoaded {
await viewModel.loadScreen()
}
}

Expand Down
12 changes: 6 additions & 6 deletions RevenueCatUI/CustomerCenter/Views/ErrorView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@ import SwiftUI
@available(watchOS, unavailable)
struct ErrorView: View {

var errorMessage: String

var body: some View {
VStack(spacing: 20) {
let errorMessage: String = Localization.localizedBundle(self.locale)
.localizedString(forKey: "Something went wrong",
value: "Something went wrong",
table: nil)
CompatibilityContentUnavailableView(
errorMessage,
String(errorMessage),
systemImage: "exclamationmark.triangle.fill",
description: nil
)
Expand All @@ -47,9 +49,7 @@ struct ErrorView: View {
struct ErrorView_Previews: PreviewProvider {

static var previews: some View {
ErrorView(errorMessage: "Something went wrong")
.padding()

ErrorView()
}
}
#endif
Expand Down

0 comments on commit e1c7637

Please sign in to comment.