-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Factor out client history & delete node buttons, and tidy up the avai…
…lable actions in the list & detail screen
- Loading branch information
Showing
5 changed files
with
204 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
Meshtastic/Views/Nodes/Helpers/Actions/ClientHistoryButton.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import SwiftUI | ||
|
||
struct ClientHistoryButton: View { | ||
var bleManager: BLEManager | ||
|
||
var connectedNode: NodeInfoEntity | ||
|
||
var node: NodeInfoEntity | ||
|
||
@State | ||
private var isPresentingAlert = false | ||
|
||
var body: some View { | ||
Button { | ||
isPresentingAlert = bleManager.requestStoreAndForwardClientHistory( | ||
fromUser: connectedNode.user!, | ||
toUser: node.user! | ||
) | ||
} label: { | ||
Label( | ||
"Client History", | ||
systemImage: "envelope.arrow.triangle.branch" | ||
) | ||
}.alert( | ||
"Client History Request Sent", | ||
isPresented: $isPresentingAlert | ||
) { | ||
Button("OK") { }.keyboardShortcut(.defaultAction) | ||
} message: { | ||
Text("Any missed messages will be delivered again.") | ||
} | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
Meshtastic/Views/Nodes/Helpers/Actions/DeleteNodeButton.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import CoreData | ||
import OSLog | ||
import SwiftUI | ||
|
||
struct DeleteNodeButton: View { | ||
var bleManager: BLEManager | ||
|
||
var context: NSManagedObjectContext | ||
|
||
var connectedNode: NodeInfoEntity | ||
|
||
var node: NodeInfoEntity | ||
|
||
@State | ||
private var isPresentingAlert = false | ||
|
||
var body: some View { | ||
Button(role: .destructive) { | ||
isPresentingAlert = true | ||
} label: { | ||
Label { | ||
Text("Delete Node") | ||
} icon: { | ||
Image(systemName: "trash") | ||
.symbolRenderingMode(.multicolor) | ||
} | ||
} | ||
.confirmationDialog( | ||
"are.you.sure", | ||
isPresented: $isPresentingAlert, | ||
titleVisibility: .visible | ||
) { | ||
Button("Delete Node", role: .destructive) { | ||
guard let deleteNode = getNodeInfo( | ||
id: node.num, | ||
context: context | ||
) else { | ||
Logger.data.error("Unable to find node info to delete node \(node.num)") | ||
return | ||
} | ||
let success = bleManager.removeNode( | ||
node: deleteNode, | ||
connectedNodeNum: connectedNode.num | ||
) | ||
if !success { | ||
Logger.data.error("Failed to delete node \(deleteNode.user?.longName ?? "unknown".localized)") | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.