mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Move DateFormatter to static let and use @State for export filename
Addresses review feedback: avoids creating a new DateFormatter on every SwiftUI body recomputation by using a static let, and captures the timestamp once per export via a @State property.
This commit is contained in:
parent
fac4b55242
commit
52d98cc283
1 changed files with 8 additions and 1 deletions
|
|
@ -21,9 +21,15 @@ struct AppLog: View {
|
|||
@State private var levels: Set<Int> = []
|
||||
@State var isExporting = false
|
||||
@State var exportString = ""
|
||||
@State var exportFilename = "Meshtastic Application Logs"
|
||||
@State var isEditingFilters = false
|
||||
|
||||
private var idiom: UIUserInterfaceIdiom { UIDevice.current.userInterfaceIdiom }
|
||||
private static let logFileDateFormatter: DateFormatter = {
|
||||
let f = DateFormatter()
|
||||
f.dateFormat = "yyyy-MM-dd_HHmmss"
|
||||
return f
|
||||
}()
|
||||
private let dateFormatStyle = Date.FormatStyle()
|
||||
.hour(.twoDigits(amPM: .omitted))
|
||||
.minute()
|
||||
|
|
@ -171,7 +177,7 @@ struct AppLog: View {
|
|||
isPresented: $isExporting,
|
||||
document: CsvDocument(emptyCsv: exportString),
|
||||
contentType: .commaSeparatedText,
|
||||
defaultFilename: "Meshtastic Application Logs \({ let f = DateFormatter(); f.dateFormat = "yyyy-MM-dd_HHmmss"; return f.string(from: .now) }())",
|
||||
defaultFilename: exportFilename,
|
||||
onCompletion: { result in
|
||||
switch result {
|
||||
case .success:
|
||||
|
|
@ -200,6 +206,7 @@ struct AppLog: View {
|
|||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
Button(action: {
|
||||
exportString = logToCsvFile(log: logs)
|
||||
exportFilename = "Meshtastic Application Logs \(Self.logFileDateFormatter.string(from: .now))"
|
||||
isExporting = true
|
||||
}) {
|
||||
Image(systemName: "square.and.arrow.down")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue