mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
* Add SwiftUI previews for simple helper views Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/a2a43e8c-24fd-443a-8a98-13b678770edd Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Add previews for action buttons, ChannelForm, MetricsColumnDetail, and DeviceOnboarding Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/a2a43e8c-24fd-443a-8a98-13b678770edd Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Add previews for config views, log views, AppLog, Firmware, AppData, and UserConfig Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/a2a43e8c-24fd-443a-8a98-13b678770edd Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Add preview for PositionConfig Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/a2a43e8c-24fd-443a-8a98-13b678770edd Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Fix formatting bugs in #Preview blocks: restore missing .environmentObject/.environment modifiers and add proper tab indentation Agent-Logs-Url: https://github.com/meshtastic/Meshtastic-Apple/sessions/7eeb7a54-7928-466f-8e39-b00d0012a09d Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> * Linting fixes --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: garthvh <1795163+garthvh@users.noreply.github.com> Co-authored-by: Garth Vander Houwen <garthvh@yahoo.com>
77 lines
1.9 KiB
Swift
77 lines
1.9 KiB
Swift
import CoreData
|
|
import OSLog
|
|
import SwiftUI
|
|
|
|
struct DeleteNodeButton: View {
|
|
|
|
@Environment(\.managedObjectContext) var context
|
|
@EnvironmentObject var accessoryManager: AccessoryManager
|
|
|
|
var connectedNode: NodeInfoEntity
|
|
var node: NodeInfoEntity
|
|
@Environment(\.dismiss) private var dismiss
|
|
@State private var isPresentingAlert = false
|
|
|
|
var body: some View {
|
|
if node.num != connectedNode.num {
|
|
Button(role: .destructive) {
|
|
isPresentingAlert = true
|
|
} label: {
|
|
Label {
|
|
Text("Delete Node")
|
|
} icon: {
|
|
Image(systemName: "trash")
|
|
.symbolRenderingMode(.multicolor)
|
|
}
|
|
}
|
|
.alert(
|
|
"Are you sure?",
|
|
isPresented: $isPresentingAlert
|
|
) {
|
|
Button("OK") { }.keyboardShortcut(.defaultAction)
|
|
} message: {
|
|
Text("Delete Node?")
|
|
}
|
|
.confirmationDialog(
|
|
"Are you sure?",
|
|
isPresented: $isPresentingAlert,
|
|
titleVisibility: .visible
|
|
) {
|
|
Button("Delete Node", role: .destructive) {
|
|
guard let deleteNode = getNodeInfo(
|
|
id: node.num,
|
|
context: context
|
|
) else {
|
|
Logger.data.error("Unable to find node info to delete node \(node.num, privacy: .public)")
|
|
return
|
|
}
|
|
|
|
Task {
|
|
do {
|
|
try await accessoryManager.removeNode(
|
|
node: deleteNode,
|
|
connectedNodeNum: connectedNode.num
|
|
)
|
|
Task {@MainActor in
|
|
dismiss()
|
|
}
|
|
} catch {
|
|
Logger.data.error("Failed to delete node \(deleteNode.user?.longName ?? "Unknown".localized, privacy: .public)")
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
let context = PersistenceController.preview.container.viewContext
|
|
let connectedNode = NodeInfoEntity(context: context)
|
|
connectedNode.num = 987654321
|
|
let node = NodeInfoEntity(context: context)
|
|
node.num = 123456789
|
|
return DeleteNodeButton(connectedNode: connectedNode, node: node)
|
|
.environmentObject(AccessoryManager.shared)
|
|
.environment(\.managedObjectContext, context)
|
|
}
|