72 lines
2.3 KiB
Swift
72 lines
2.3 KiB
Swift
import SwiftUI
|
|
|
|
public struct FeatureRootView: View {
|
|
@State private var model: FeatureRootModel
|
|
|
|
public init(client: any FeatureClient) {
|
|
_model = State(initialValue: FeatureRootModel(client: client))
|
|
}
|
|
|
|
public var body: some View {
|
|
Group {
|
|
if model.isLoading {
|
|
FeatureLoadingView()
|
|
} else if shouldShowWorkspace {
|
|
WorkspaceView(
|
|
model: model,
|
|
submitNewTask: { request in
|
|
await model.startTask(request)
|
|
},
|
|
submitMessage: { submission in
|
|
await model.sendMessage(submission)
|
|
}
|
|
)
|
|
} else {
|
|
ConnectionOnboardingView(model: model)
|
|
}
|
|
}
|
|
.preferredColorScheme(model.snapshot.settings.appearance == .dark ? .dark : nil)
|
|
.tint(.white)
|
|
.background(Color.black.ignoresSafeArea())
|
|
.task { await model.start() }
|
|
.alert(
|
|
"Something went wrong",
|
|
isPresented: Binding(
|
|
get: { model.errorMessage != nil },
|
|
set: { if !$0 { model.errorMessage = nil } }
|
|
),
|
|
actions: {
|
|
Button("OK") { model.errorMessage = nil }
|
|
},
|
|
message: {
|
|
Text(model.errorMessage ?? "Unknown error")
|
|
}
|
|
)
|
|
}
|
|
|
|
/// Keep the last-known workspace visible through a degraded connection.
|
|
/// A deliberate disconnect clears workspace data and returns to onboarding.
|
|
private var shouldShowWorkspace: Bool {
|
|
model.snapshot.connection.state != .disconnected
|
|
|| !model.snapshot.projects.isEmpty
|
|
|| !model.snapshot.threads.isEmpty
|
|
}
|
|
}
|
|
|
|
private struct FeatureLoadingView: View {
|
|
var body: some View {
|
|
VStack(spacing: 14) {
|
|
Image(systemName: "chevron.left.forwardslash.chevron.right")
|
|
.font(.system(size: 30, weight: .semibold))
|
|
ProgressView()
|
|
.controlSize(.small)
|
|
Text("Connecting to T3 Code")
|
|
.font(.footnote)
|
|
.foregroundStyle(.secondary)
|
|
}
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
.background(Color.black)
|
|
.accessibilityElement(children: .combine)
|
|
}
|
|
}
|