refactored code structure
This commit is contained in:
70
Sources/Views/ServerDetailView.swift
Normal file
70
Sources/Views/ServerDetailView.swift
Normal file
@@ -0,0 +1,70 @@
|
||||
//
|
||||
// ServerDetailView.swift
|
||||
// iKeyMon
|
||||
//
|
||||
// Created by tracer on 30.03.25.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ServerDetailView: View {
|
||||
@Binding var server: Server
|
||||
var isFetching: Bool
|
||||
|
||||
@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) {
|
||||
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
|
||||
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
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user