1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
import SwiftUI
struct DomainListView: View {
@ObservedObject var viewModel: DomainViewModel
let client: NjallaClient?
var body: some View {
NavigationStack {
Group {
if let client {
content(client: client)
} else {
ContentUnavailableView("Sign in required", systemImage: "key.fill", description: Text("Add a valid Njalla API token to load domains."))
}
}
.navigationTitle("Domains")
}
}
@ViewBuilder
private func content(client: NjallaClient) -> some View {
List {
if let errorMessage = viewModel.domainsErrorMessage {
Section {
InlineErrorView(message: errorMessage, retryTitle: "Retry Domains") {
Task {
await viewModel.loadDomains(client: client)
}
}
.listRowInsets(EdgeInsets(top: 8, leading: 16, bottom: 8, trailing: 16))
}
}
if (!viewModel.hasLoadedDomains || viewModel.isLoadingDomains) && viewModel.domains.isEmpty {
Section {
HStack {
Spacer()
ProgressView("Loading Domains")
Spacer()
}
}
} else if viewModel.domains.isEmpty {
Section {
ContentUnavailableView(
"No Domains",
systemImage: "globe",
description: Text("No domains found. Pull to refresh after domains are added to this account.")
)
}
} else {
ForEach(viewModel.domains) { domain in
NavigationLink {
DomainDetailView(domainName: domain.name, viewModel: viewModel, client: client)
} label: {
DomainRow(domain: domain)
}
}
}
}
.listStyle(.insetGrouped)
.refreshable {
await viewModel.loadDomains(client: client)
}
}
}
private struct DomainRow: View {
let domain: Domain
var body: some View {
VStack(alignment: .leading, spacing: 6) {
Text(domain.name)
.font(.headline)
HStack {
if let status = domain.status {
Text(status)
}
if let expiry = domain.expiry {
Text("Expiry: \(expiry.formattedExpiry())")
}
}
.font(.subheadline)
.foregroundStyle(.secondary)
if let autorenew = domain.autorenew {
Text(autorenew ? "Autorenew On" : "Autorenew Off")
.font(.subheadline)
.foregroundStyle(.secondary)
}
}
.padding(.vertical, 4)
}
}
|