Online only filter

This commit is contained in:
Garth Vander Houwen 2024-03-26 14:57:00 -07:00
parent 35c943aa68
commit 0c112e2a55
3 changed files with 25 additions and 2 deletions

View file

@ -13,6 +13,7 @@ struct NodeListFilter: View {
/// Filters
@Binding var viaLora: Bool
@Binding var viaMqtt: Bool
@Binding var isOnline: Bool
@Binding var distanceFilter: Bool
@Binding var maximumDistance: Double
@Binding var hopsAway: Int
@ -44,6 +45,18 @@ struct NodeListFilter: View {
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
.listRowSeparator(.visible)
Toggle(isOn: $isOnline) {
Label {
Text("Online Only")
} icon: {
Image(systemName: "checkmark.circle.fill")
.foregroundColor(.green)
}
}
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
.listRowSeparator(.visible)
// Toggle(isOn: $distanceFilter) {
//
// Label {

View file

@ -19,6 +19,7 @@ struct NodeList: View {
@State private var searchText = ""
@State private var viaLora = true
@State private var viaMqtt = true
@State private var isOnline = false
@State private var distanceFilter = false
@State private var maxDistance: Double = 800000
@State private var hopsAway: Int = -1
@ -144,7 +145,7 @@ struct NodeList: View {
}
}
.sheet(isPresented: $isEditingFilters) {
NodeListFilter(viaLora: $viaLora, viaMqtt: $viaMqtt, distanceFilter: $distanceFilter, maximumDistance: $maxDistance, hopsAway: $hopsAway, deviceRole: $deviceRole)
NodeListFilter(viaLora: $viaLora, viaMqtt: $viaMqtt, isOnline: $isOnline, distanceFilter: $distanceFilter, maximumDistance: $maxDistance, hopsAway: $hopsAway, deviceRole: $deviceRole)
}
.safeAreaInset(edge: .bottom, alignment: .trailing) {
HStack {
@ -259,6 +260,9 @@ struct NodeList: View {
.onChange(of: hopsAway) { _ in
searchNodeList()
}
.onChange(of: isOnline) { _ in
searchNodeList()
}
.onAppear {
if self.bleManager.context == nil {
self.bleManager.context = context
@ -295,6 +299,12 @@ struct NodeList: View {
let hopsAwayPredicate = NSPredicate(format: "hopsAway == %i", Int32(hopsAway))
predicates.append(hopsAwayPredicate)
}
/// Online
if isOnline {
let isOnlinePredicate = NSPredicate(format: "lastHeard >= %@", Calendar.current.date(byAdding: .minute, value: -15, to: Date())! as NSDate)
predicates.append(isOnlinePredicate)
}
/// Distance
if distanceFilter {
let pointOfInterest = LocationHelper.currentLocation

View file

@ -254,7 +254,7 @@ struct MQTTConfig: View {
}
.toggleStyle(SwitchToggleStyle(tint: .accentColor))
}
Text("For all Mqtt functionality other than the map report you must also set uplink and downlink for each channel you want to brige over Mqtt.")
Text("For all Mqtt functionality other than the map report you must also set uplink and downlink for each channel you want to bridge over Mqtt.")
.font(.callout)
}
.scrollDismissesKeyboard(.interactively)