diff options
| author | Christian Cleberg <[email protected]> | 2026-03-24 21:48:23 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-03-24 21:48:23 -0500 |
| commit | cf587aa0573ac4f34e1effe70108a9eca82093ac (patch) | |
| tree | 833e6f4961522e35b08af01b5f012983f8e34678 /Rune/Views/Domains/RecordListView.swift | |
| download | rune-1.0.0.tar.gz rune-1.0.0.tar.bz2 rune-1.0.0.zip | |
v1.0v1.0.0
Diffstat (limited to 'Rune/Views/Domains/RecordListView.swift')
| -rw-r--r-- | Rune/Views/Domains/RecordListView.swift | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/Rune/Views/Domains/RecordListView.swift b/Rune/Views/Domains/RecordListView.swift new file mode 100644 index 0000000..67a4140 --- /dev/null +++ b/Rune/Views/Domains/RecordListView.swift @@ -0,0 +1,81 @@ +import SwiftUI + +struct RecordListView: View { + let domainName: String + @ObservedObject var viewModel: DomainViewModel + let client: NjallaClient + + @State private var showingAddRecord = false + + var body: some View { + Group { + if viewModel.isLoadingRecords && viewModel.records.isEmpty { + ProgressView() + } else if viewModel.records.isEmpty { + ContentUnavailableView("No Records", systemImage: "list.bullet", description: Text("No DNS records for this domain.")) + } else { + List(viewModel.records) { record in + NavigationLink { + RecordEditView(domainName: domainName, record: record, viewModel: viewModel, client: client) + } label: { + RecordRow(record: record) + } + } + .listStyle(.insetGrouped) + } + } + .navigationTitle("DNS Records") + .navigationBarTitleDisplayMode(.inline) + .toolbar { + Button { + showingAddRecord = true + } label: { + Label("Add Record", systemImage: "plus") + } + } + .sheet(isPresented: $showingAddRecord) { + NavigationStack { + RecordAddView(domainName: domainName, viewModel: viewModel, client: client) + } + } + .task { + await viewModel.loadRecords(for: domainName, client: client) + } + .refreshable { + await viewModel.loadRecords(for: domainName, client: client) + } + .alert("API Error", isPresented: errorBinding) { + Button("OK", role: .cancel) {} + } message: { + Text(viewModel.errorMessage ?? "") + } + } + + private var errorBinding: Binding<Bool> { + Binding( + get: { viewModel.errorMessage != nil }, + set: { newValue in + if !newValue { + viewModel.errorMessage = nil + } + } + ) + } +} + +private struct RecordRow: View { + let record: DNSRecord + + var body: some View { + VStack(alignment: .leading, spacing: 4) { + Text("\(record.type) \(record.name)") + .font(.headline) + if let detail = [record.content, record.target].compactMap({ $0 }).first, !detail.isEmpty { + Text(detail) + .font(.subheadline) + .foregroundStyle(.secondary) + } + } + .padding(.vertical, 4) + } +} |
