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>
71 lines
2 KiB
Swift
71 lines
2 KiB
Swift
import CoreData
|
|
import SwiftUI
|
|
import OSLog
|
|
|
|
struct ExchangeUserInfoButton: View {
|
|
var node: NodeInfoEntity
|
|
var connectedNode: NodeInfoEntity
|
|
|
|
@EnvironmentObject var accessoryManager: AccessoryManager
|
|
|
|
@State private var isPresentingUserInfoSentAlert: Bool = false
|
|
@State private var isPresentingUserInfoFailedAlert: Bool = false
|
|
|
|
var body: some View {
|
|
Button {
|
|
Task {
|
|
if let fromUser = connectedNode.user, let toUser = node.user {
|
|
do {
|
|
_ = try await accessoryManager.exchangeUserInfo(fromUser: fromUser, toUser: toUser)
|
|
Task { @MainActor in
|
|
isPresentingUserInfoSentAlert = true
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
|
|
isPresentingUserInfoSentAlert = false
|
|
}
|
|
}
|
|
} catch {
|
|
Logger.mesh.warning("Failed to exchange user info")
|
|
Task { @MainActor in
|
|
isPresentingUserInfoFailedAlert = true
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
|
|
isPresentingUserInfoFailedAlert = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
} label: {
|
|
Label {
|
|
Text("Exchange User Info")
|
|
} icon: {
|
|
Image(systemName: "person.2.badge.gearshape")
|
|
.symbolRenderingMode(.hierarchical)
|
|
}
|
|
}.alert(
|
|
"User Info Sent",
|
|
isPresented: $isPresentingUserInfoSentAlert
|
|
) {
|
|
Button("OK") { }.keyboardShortcut(.defaultAction)
|
|
} message: {
|
|
Text("Your user info has been sent with a request for a response with their user info.")
|
|
}.alert(
|
|
"User Info Exchange Failed",
|
|
isPresented: $isPresentingUserInfoFailedAlert
|
|
) {
|
|
Button("OK") { }.keyboardShortcut(.defaultAction)
|
|
} message: {
|
|
Text("Failed to exchange user info.")
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
let context = PersistenceController.preview.container.viewContext
|
|
let node = NodeInfoEntity(context: context)
|
|
node.num = 123456789
|
|
let connectedNode = NodeInfoEntity(context: context)
|
|
connectedNode.num = 987654321
|
|
return ExchangeUserInfoButton(node: node, connectedNode: connectedNode)
|
|
.environmentObject(AccessoryManager.shared)
|
|
}
|