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>
62 lines
1.5 KiB
Swift
62 lines
1.5 KiB
Swift
import CoreData
|
|
import OSLog
|
|
import SwiftUI
|
|
|
|
struct IgnoreNodeButton: View {
|
|
@Environment(\.managedObjectContext) var context
|
|
@EnvironmentObject var accessoryManager: AccessoryManager
|
|
|
|
@ObservedObject
|
|
var node: NodeInfoEntity
|
|
|
|
var body: some View {
|
|
Button(role: .destructive) {
|
|
guard let connectedNodeNum = accessoryManager.activeDeviceNum else { return }
|
|
Task {
|
|
do {
|
|
if node.ignored {
|
|
try await accessoryManager.removeIgnoredNode(
|
|
node: node,
|
|
connectedNodeNum: Int64(connectedNodeNum)
|
|
)
|
|
} else {
|
|
try await accessoryManager.setIgnoredNode(
|
|
node: node,
|
|
connectedNodeNum: Int64(connectedNodeNum)
|
|
)
|
|
}
|
|
Task {@MainActor in
|
|
// CoreData Stuff
|
|
node.ignored = !node.ignored
|
|
do {
|
|
try context.save()
|
|
} catch {
|
|
context.rollback()
|
|
Logger.data.error("Save Ignored Node Error")
|
|
}
|
|
}
|
|
Logger.data.debug("Ignored a node")
|
|
} catch {
|
|
Logger.mesh.error("Faile to Ignored/Un-ignore a node")
|
|
}
|
|
}
|
|
} label: {
|
|
Label {
|
|
Text(node.ignored ? "Remove from ignored" : "Ignore Node")
|
|
} icon: {
|
|
Image(systemName: node.ignored ? "minus.circle.fill" : "minus.circle")
|
|
.symbolRenderingMode(.multicolor)
|
|
}
|
|
// Accessibility: Label for VoiceOver
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
let context = PersistenceController.preview.container.viewContext
|
|
let node = NodeInfoEntity(context: context)
|
|
node.num = 123456789
|
|
return IgnoreNodeButton(node: node)
|
|
.environmentObject(AccessoryManager.shared)
|
|
.environment(\.managedObjectContext, context)
|
|
}
|