summaryrefslogtreecommitdiff
path: root/Rune/Views/Domains/RecordAddView.swift
diff options
context:
space:
mode:
authorChristian Cleberg <[email protected]>2026-04-11 11:48:40 -0500
committerChristian Cleberg <[email protected]>2026-04-11 11:48:40 -0500
commitfcf864a15b70e4ecb5bd789b1db3116221c34394 (patch)
treef15315324b9f95286b6bf7392dd0ccaee210c2de /Rune/Views/Domains/RecordAddView.swift
parentcf587aa0573ac4f34e1effe70108a9eca82093ac (diff)
downloadrune-fcf864a15b70e4ecb5bd789b1db3116221c34394.tar.gz
rune-fcf864a15b70e4ecb5bd789b1db3116221c34394.tar.bz2
rune-fcf864a15b70e4ecb5bd789b1db3116221c34394.zip
add FUNDING.yml
Diffstat (limited to 'Rune/Views/Domains/RecordAddView.swift')
-rw-r--r--Rune/Views/Domains/RecordAddView.swift37
1 files changed, 25 insertions, 12 deletions
diff --git a/Rune/Views/Domains/RecordAddView.swift b/Rune/Views/Domains/RecordAddView.swift
index 8dfa81d..2cc5dde 100644
--- a/Rune/Views/Domains/RecordAddView.swift
+++ b/Rune/Views/Domains/RecordAddView.swift
@@ -8,7 +8,6 @@ struct RecordAddView: View {
@Environment(\.dismiss) private var dismiss
@State private var draft = DNSRecordDraft()
- @State private var localErrorMessage: String?
var body: some View {
Form {
DNSRecordFormSections(draft: $draft)
@@ -24,44 +23,54 @@ struct RecordAddView: View {
}
.navigationTitle("Add Record")
.navigationBarTitleDisplayMode(.inline)
+ .overlay {
+ if viewModel.isSaving {
+ ProgressView()
+ .controlSize(.large)
+ }
+ }
.toolbar {
ToolbarItem(placement: .cancellationAction) {
Button("Cancel", role: .cancel) {
dismiss()
}
+ .disabled(viewModel.isSaving)
}
}
+ .interactiveDismissDisabled(viewModel.isSaving)
.onChange(of: draft.type) { oldValue, newValue in
guard oldValue != newValue else { return }
draft.resetTypeSpecificFields()
}
- .alert("API Error", isPresented: localErrorBinding) {
+ .alert("Request Failed", isPresented: mutationErrorBinding) {
Button("OK", role: .cancel) {}
} message: {
- Text(localErrorMessage ?? "")
+ Text(viewModel.mutationErrorMessage ?? "")
}
}
private func save() async {
+ guard !viewModel.isSaving else {
+ return
+ }
+
do {
try await viewModel.addRecord(for: domainName, draft: draft, client: client)
+ draft = DNSRecordDraft()
dismiss()
} catch is CancellationError {
return
} catch {
- if (error as? URLError)?.code == .cancelled {
- return
- }
- localErrorMessage = error.localizedDescription
+ return
}
}
- private var localErrorBinding: Binding<Bool> {
+ private var mutationErrorBinding: Binding<Bool> {
Binding(
- get: { localErrorMessage != nil },
+ get: { viewModel.mutationErrorMessage != nil },
set: { newValue in
if !newValue {
- localErrorMessage = nil
+ viewModel.dismissMutationError()
}
}
)
@@ -94,8 +103,12 @@ struct DNSRecordFormSections: View {
if draft.type.usesTTL {
Section("TTL") {
- TextField("TTL", text: $draft.ttl)
- .keyboardType(.numberPad)
+ Picker("TTL", selection: $draft.ttlSeconds) {
+ ForEach(draft.ttlOptions) { option in
+ Text(option.isCustom ? "Custom (\(option.label))" : option.label)
+ .tag(option.seconds)
+ }
+ }
}
}