From ce4734b07b9ad5ff1692d79d2a11fb65f1e01919 Mon Sep 17 00:00:00 2001 From: Fabrizio Demaria Date: Fri, 29 Nov 2024 17:29:58 +0100 Subject: [PATCH] feat: Demo app waits for experience --- .../ConfidenceDemoApp/ContentView.swift | 48 ++++++++++++------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/ConfidenceDemoApp/ConfidenceDemoApp/ContentView.swift b/ConfidenceDemoApp/ConfidenceDemoApp/ContentView.swift index 07793c96..6aec74cd 100644 --- a/ConfidenceDemoApp/ConfidenceDemoApp/ContentView.swift +++ b/ConfidenceDemoApp/ConfidenceDemoApp/ContentView.swift @@ -6,34 +6,46 @@ struct ContentView: View { @EnvironmentObject var status: ExperimentationFlags @AppStorage("loggedUser") private var loggedUser: String? @State var isLoggingOut: Bool = false + @State var loggedOut: Bool = false - private let color: Color private let confidence: Confidence init(confidence: Confidence) { self.confidence = confidence - self.color = ContentView.getColor(color: confidence.getValue(key: "swift-demoapp.color", defaultValue: "Gray")) } var body: some View { NavigationStack { - VStack { - Text("Hello World!") - .foregroundStyle(color) - } - .padding() - Button("Logout") { - loggedUser = nil - status.state = .loading - Task { - await confidence.removeContext(key: "user_id") - status.state = .ready + if (status.state == .loading && !isLoggingOut) { + VStack { + Spacer() + Text("Welcome \(loggedUser ?? "?")") + Text("We are preparing your experience...") + ProgressView() + Spacer() + } + } else { + VStack { + Text("Hello World!") + .font(.largeTitle) + .foregroundStyle(ContentView.getColor(color: confidence.getValue(key: "swift-demoapp.color", defaultValue: "Gray"))) + } + .padding() + Button("Logout") { + isLoggingOut = true + + loggedUser = nil + status.state = .loading + Task { + await confidence.removeContext(key: "user_id") + status.state = .ready + } + loggedUser = nil + loggedOut = true + } + .navigationDestination(isPresented: $loggedOut) { + LoginView(confidence: confidence) } - loggedUser = nil - isLoggingOut = true - } - .navigationDestination(isPresented: $isLoggingOut) { - LoginView(confidence: confidence) } } }