75 lines
2.4 KiB
Swift
75 lines
2.4 KiB
Swift
//
|
|
// ServerDetailView.swift
|
|
// iKeyMon
|
|
//
|
|
// Created by tracer on 30.03.25.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct ServerDetailView: View {
|
|
@Binding var server: Server
|
|
var isFetching: Bool
|
|
@AppStorage("showIntervalIndicator") private var showIntervalIndicator: Bool = true
|
|
|
|
@State private var progress: Double = 0
|
|
let timer = Timer.publish(every: 1.0 / 60.0, on: .main, in: .common).autoconnect()
|
|
|
|
var body: some View {
|
|
VStack(spacing: 0) {
|
|
if showIntervalIndicator {
|
|
ProgressView(value: progress)
|
|
.progressViewStyle(LinearProgressViewStyle())
|
|
.padding(.horizontal)
|
|
.frame(height: 2)
|
|
}
|
|
|
|
if server.info == nil {
|
|
ProgressView("Fetching server info...")
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
} else {
|
|
ZStack(alignment: .topTrailing) {
|
|
VStack(spacing: 0) {
|
|
Spacer().frame(height: 6)
|
|
TabView {
|
|
GeneralView(server: $server)
|
|
.tabItem {
|
|
Text("General")
|
|
}
|
|
ResourcesView(server: $server)
|
|
.tabItem {
|
|
Text("Resources")
|
|
}
|
|
ServicesView(server: $server)
|
|
.tabItem {
|
|
Text("Services")
|
|
}
|
|
}
|
|
}
|
|
|
|
if isFetching {
|
|
ProgressView()
|
|
.scaleEffect(0.5)
|
|
.padding()
|
|
}
|
|
}
|
|
.padding(0)
|
|
}
|
|
}
|
|
.onReceive(timer) { _ in
|
|
guard showIntervalIndicator else { return }
|
|
withAnimation(.linear(duration: 1.0 / 60.0)) {
|
|
progress += 1.0 / (60.0 * 60.0)
|
|
if progress >= 1 { progress = 0 }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
ServerDetailView(
|
|
server: .constant(Server(id: UUID(), hostname: "preview.example.com", info: ServerInfo.placeholder)),
|
|
isFetching: false
|
|
)
|
|
}
|