Files
jarvis/Jarvis/Views/Shared/ConnectionBanner.swift

61 lines
1.7 KiB
Swift
Raw Normal View History

// ConnectionBanner.swift
// Jarvis Live / Offline / Reconnecting indicator driven by WebSocketManager.
import SwiftUI
extension ConnectionState {
var isLive: Bool {
if case .connected = self { return true }
return false
}
var label: String {
switch self {
case .connected: return "Live"
case .connecting: return "Connecting"
case .reconnecting: return "Reconnecting"
case .disconnected: return "Offline"
}
}
var dotColor: Color {
switch self {
case .connected: return Color(hex: "33C25E")
case .connecting,
.reconnecting: return Palette.healthFailing
case .disconnected: return Color(hex: "555555")
}
}
}
/// Compact Live/Offline pill a colored dot + state label.
struct ConnectionBanner: View {
let state: ConnectionState
var body: some View {
HStack(spacing: 6) {
Circle()
.fill(state.dotColor)
.frame(width: 7, height: 7)
Text(state.label.uppercased())
.font(.system(size: 11, weight: .bold))
.kerning(0.6)
.foregroundStyle(state.isLive ? Color(hex: "33C25E") : Color(hex: "888888"))
}
.padding(.horizontal, 10)
.padding(.vertical, 5)
.background(Palette.surface)
.clipShape(Capsule())
}
}
#Preview {
VStack(spacing: 12) {
ConnectionBanner(state: .connected)
ConnectionBanner(state: .reconnecting(attempt: 2))
ConnectionBanner(state: .disconnected)
}
.padding()
.background(Color.black)
}