48 lines
1.5 KiB
Swift
48 lines
1.5 KiB
Swift
import SwiftUI
|
|
|
|
struct ContentView: View {
|
|
@StateObject private var session: AuthSessionStore
|
|
private let restoresSession: Bool
|
|
|
|
@MainActor init(session: AuthSessionStore? = nil, restoresSession: Bool = true) {
|
|
_session = StateObject(wrappedValue: session ?? AuthSessionStore.shared)
|
|
self.restoresSession = restoresSession
|
|
#if DEBUG
|
|
print("[ContentView] initialized; injectedSession=\(session != nil), restoresSession=\(restoresSession)")
|
|
#endif
|
|
}
|
|
|
|
var body: some View {
|
|
Group {
|
|
switch session.state {
|
|
case .checking:
|
|
ProgressView()
|
|
.tint(.red)
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
.background(Color(uiColor: .systemBackground))
|
|
.accessibilityLabel("Checking sign-in")
|
|
case .signedOut:
|
|
SignInView(session: session)
|
|
case .signedIn:
|
|
MainTabView()
|
|
}
|
|
}
|
|
.task {
|
|
guard restoresSession else { return }
|
|
#if DEBUG
|
|
print("[ContentView] session restore task started")
|
|
defer {
|
|
print("[ContentView] session restore task ended; cancelled=\(Task.isCancelled)")
|
|
}
|
|
#endif
|
|
await session.restoreSession()
|
|
}
|
|
}
|
|
}
|
|
|
|
struct ContentView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
ContentView()
|
|
}
|
|
}
|