mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
61 lines
1.8 KiB
Swift
61 lines
1.8 KiB
Swift
//
|
|
// DeviceHome.swift
|
|
// MeshtasticClient
|
|
//
|
|
// Created by Garth Vander Houwen on 8/7/21.
|
|
//
|
|
|
|
// Abstract:
|
|
// A view showing a list of devices that have been seen on the mesh network
|
|
|
|
import SwiftUI
|
|
|
|
struct NodeList: View {
|
|
@EnvironmentObject var bleManager: BLEManager
|
|
@EnvironmentObject var meshData: MeshData
|
|
|
|
@State private var showLocationOnly = false
|
|
|
|
var filteredDevices: [NodeInfoModel] {
|
|
meshData.nodes.filter { node in
|
|
(!showLocationOnly || node.position.coordinate != nil)
|
|
}
|
|
}
|
|
|
|
var body: some View {
|
|
NavigationView {
|
|
|
|
List {
|
|
Toggle(isOn: $showLocationOnly) {
|
|
Text("Nodes with location only")
|
|
}
|
|
ForEach(filteredDevices.sorted(by: { $0.lastHeard > $1.lastHeard })) { node in
|
|
NavigationLink(destination: NodeDetail(node: node)) {
|
|
NodeRow(node: node, index : 0)
|
|
|
|
}
|
|
.swipeActions {
|
|
Button {
|
|
let nodeIndex = meshData.nodes.firstIndex(where: { $0.id == node.id })
|
|
meshData.nodes.remove(at: nodeIndex!)
|
|
meshData.save()
|
|
} label: {
|
|
VStack {
|
|
Label("Delete from app", systemImage: "trash")
|
|
}
|
|
}
|
|
.tint(.red)
|
|
}
|
|
}
|
|
}
|
|
.navigationTitle("All Nodes")
|
|
}
|
|
}
|
|
}
|
|
|
|
struct NodeList_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
NodeList()
|
|
.environmentObject(MeshData())
|
|
}
|
|
}
|