2026-09-20 15:05:19 +02:00
|
|
|
// KeeVault/Views/EntryEditView.swift
|
2026-09-19 16:00:37 +02:00
|
|
|
import SwiftUI
|
2026-09-20 15:05:19 +02:00
|
|
|
import KeeVaultCore
|
2026-09-19 16:00:37 +02:00
|
|
|
|
|
|
|
|
struct EntryEditView: View {
|
|
|
|
|
@ObservedObject var vm: EntryEditViewModel
|
|
|
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
|
NavigationStack {
|
|
|
|
|
Form {
|
2026-09-19 17:02:03 +02:00
|
|
|
if !vm.isEditing {
|
|
|
|
|
Section("Group") {
|
|
|
|
|
Picker("Group", selection: $vm.groupId) {
|
|
|
|
|
ForEach(vm.flatGroups) { flatGroup in
|
|
|
|
|
Text(groupLabel(for: flatGroup)).tag(flatGroup.group.id)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-19 16:00:37 +02:00
|
|
|
Section("Credentials") {
|
|
|
|
|
TextField("Title", text: $vm.title)
|
|
|
|
|
TextField("Username", text: $vm.username)
|
|
|
|
|
.textContentType(.username)
|
|
|
|
|
.autocorrectionDisabled()
|
|
|
|
|
SecureField("Password", text: $vm.password)
|
|
|
|
|
.textContentType(.password)
|
|
|
|
|
TextField("URL", text: $vm.url)
|
|
|
|
|
.textContentType(.URL)
|
|
|
|
|
#if os(iOS)
|
|
|
|
|
.keyboardType(.URL)
|
|
|
|
|
#endif
|
|
|
|
|
.autocorrectionDisabled()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Section("Notes") {
|
|
|
|
|
TextEditor(text: $vm.notes)
|
|
|
|
|
.frame(minHeight: 80)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Section {
|
|
|
|
|
ForEach($vm.customFields) { $field in
|
|
|
|
|
HStack {
|
|
|
|
|
TextField("Key", text: $field.key)
|
|
|
|
|
Divider()
|
|
|
|
|
TextField("Value", text: Binding(
|
|
|
|
|
get: { field.value.reveal() },
|
|
|
|
|
set: { field.value = ProtectedString($0, isProtected: field.value.isProtected) }
|
|
|
|
|
))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.onDelete(perform: vm.removeCustomField)
|
|
|
|
|
Button("Add Field", action: vm.addCustomField)
|
|
|
|
|
} header: {
|
|
|
|
|
Text("Custom Fields")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if let msg = vm.errorMessage {
|
|
|
|
|
Section { Text(msg).foregroundStyle(.red) }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
.navigationTitle(vm.isEditing ? "Edit Entry" : "New Entry")
|
|
|
|
|
#if os(iOS)
|
|
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
|
|
|
#endif
|
|
|
|
|
.toolbar {
|
|
|
|
|
ToolbarItem(placement: .cancellationAction) {
|
|
|
|
|
Button("Cancel") { dismiss() }
|
|
|
|
|
}
|
|
|
|
|
ToolbarItem(placement: .confirmationAction) {
|
|
|
|
|
Button("Save") { vm.save { dismiss() } }
|
|
|
|
|
.disabled(vm.title.isEmpty || vm.isSaving)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-09-19 17:02:03 +02:00
|
|
|
|
|
|
|
|
private func groupLabel(for flatGroup: FlatGroup) -> String {
|
|
|
|
|
(flatGroup.breadcrumb.map(\.name) + [flatGroup.group.name]).joined(separator: " > ")
|
|
|
|
|
}
|
2026-09-19 16:00:37 +02:00
|
|
|
}
|