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>
68 lines
2.1 KiB
Swift
68 lines
2.1 KiB
Swift
//
|
|
// NavigateToButton.swift
|
|
// Meshtastic
|
|
//
|
|
// Created by Benjamin Faershtein on 2/8/25.
|
|
//
|
|
|
|
import SwiftUI
|
|
import CoreLocation
|
|
import CoreData
|
|
import OSLog
|
|
|
|
struct NavigateToButton: View {
|
|
var node: NodeInfoEntity
|
|
|
|
var body: some View {
|
|
Button {
|
|
guard let userNum = node.user?.num else {
|
|
Logger.services.error("NavigateToAction: Selected node does not exist")
|
|
return
|
|
}
|
|
Logger.services.info("Fetching NodeInfoEntity for userNum: \(userNum, privacy: .public)")
|
|
|
|
let fetchRequest: NSFetchRequest<NodeInfoEntity> = NSFetchRequest(entityName: "NodeInfoEntity")
|
|
fetchRequest.predicate = NSPredicate(format: "num == %lld", Int64(userNum))
|
|
|
|
do {
|
|
let fetchedNodes = try PersistenceController.shared.container.viewContext.fetch(fetchRequest)
|
|
guard let nodeInfo = fetchedNodes.first else {
|
|
Logger.services.error("NavigateToAction: Node with userNum \(userNum, privacy: .public) not found in Core Data")
|
|
return
|
|
}
|
|
|
|
if let latitude = nodeInfo.latestPosition?.latitude,
|
|
let longitude = nodeInfo.latestPosition?.longitude {
|
|
if let url = URL(string: "maps://?saddr=&daddr=\(latitude),\(longitude)") {
|
|
UIApplication.shared.open(url, options: [:], completionHandler: nil)
|
|
} else {
|
|
Logger.services.error("Failed to create URL for navigation")
|
|
}
|
|
} else {
|
|
Logger.services.warning("NavigateToAction: Node \(userNum, privacy: .public) has invalid or missing coordinates")
|
|
}
|
|
} catch {
|
|
Logger.services.error("NavigateToAction: Failed to fetch node with userNum \(userNum, privacy: .public): \(error.localizedDescription, privacy: .public)")
|
|
}
|
|
} label: {
|
|
Label {
|
|
Text("Navigate to node")
|
|
} icon: {
|
|
Image(systemName: "map")
|
|
.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"
|
|
user.num = 123456789
|
|
node.user = user
|
|
return NavigateToButton(node: node)
|
|
}
|