Meshtastic-Apple/Meshtastic/Views/Nodes/Helpers/Actions/NodeAlertsButton.swift
Copilot c388bf9b40 Add missing SwiftUI #Preview blocks across 65 views (#1649)
* 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>
2026-04-16 06:06:55 +00:00

44 lines
949 B
Swift

import CoreData
import OSLog
import SwiftUI
struct NodeAlertsButton: View {
var context: NSManagedObjectContext
@ObservedObject
var node: NodeInfoEntity
@ObservedObject
var user: UserEntity
var body: some View {
Button {
user.mute = !user.mute
context.refresh(node, mergeChanges: true)
do {
try context.save()
} catch {
context.rollback()
Logger.data.error("Save User Mute Error")
}
} label: {
Label {
Text(user.mute ? "Show alerts" : "Hide alerts")
} icon: {
Image(systemName: user.mute ? "bell.slash" : "bell")
.symbolRenderingMode(.hierarchical)
}
}
}
}
#Preview {
let context = PersistenceController.preview.container.viewContext
let node = NodeInfoEntity(context: context)
node.num = 123456789
let user = UserEntity(context: context)
user.longName = "Test Node"
user.shortName = "TN"
node.user = user
return NodeAlertsButton(context: context, node: node, user: user)
}