Merge pull request #779 from meshtastic/fix-last-heard-list

revert the last heard text changes on the list view, since that impacts performace
This commit is contained in:
Blake McAnally 2024-07-09 21:32:55 -05:00 committed by GitHub
commit 0dc5f5574a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 13 deletions

View file

@ -8,15 +8,9 @@ import SwiftUI
struct LastHeardText: View {
var lastHeard: Date?
static let formatter: RelativeDateTimeFormatter = {
let formatter = RelativeDateTimeFormatter()
formatter.unitsStyle = .full
return formatter
}()
var body: some View {
if let lastHeard, lastHeard.timeIntervalSince1970 > 0, let text = Self.formatter.string(for: lastHeard) {
Text(text)
if let lastHeard, lastHeard.timeIntervalSince1970 > 0 {
Text(lastHeard.formatted())
} else {
Text("unknown")
}

View file

@ -10,11 +10,17 @@ import CoreLocation
import OSLog
struct NodeDetail: View {
private static let relativeFormatter: RelativeDateTimeFormatter = {
let formatter = RelativeDateTimeFormatter()
formatter.unitsStyle = .full
return formatter
}()
@Environment(\.managedObjectContext) var context
@EnvironmentObject var bleManager: BLEManager
@State private var showingShutdownConfirm: Bool = false
@State private var showingRebootConfirm: Bool = false
@State private var dateFormatRelative: Bool = true
// The node the device is currently connected to
var connectedNode: NodeInfoEntity?
@ -138,9 +144,15 @@ struct NodeDetail: View {
.symbolRenderingMode(.multicolor)
}
Spacer()
LastHeardText(lastHeard: firstHeard)
.textSelection(.enabled)
if dateFormatRelative, let text = Self.relativeFormatter.string(for: firstHeard) {
Text(text)
.textSelection(.enabled)
} else {
Text(firstHeard.formatted())
.textSelection(.enabled)
}
}.onTapGesture {
dateFormatRelative.toggle()
}
}
@ -154,8 +166,15 @@ struct NodeDetail: View {
}
Spacer()
LastHeardText(lastHeard: lastHeard)
.textSelection(.enabled)
if dateFormatRelative, let text = Self.relativeFormatter.string(for: lastHeard) {
Text(text)
.textSelection(.enabled)
} else {
Text(lastHeard.formatted())
.textSelection(.enabled)
}
}.onTapGesture {
dateFormatRelative.toggle()
}
}
}