aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIván Ávalos <avalos@disroot.org>2022-02-08 22:01:58 -0600
committerIván Ávalos <avalos@disroot.org>2022-02-08 22:01:58 -0600
commit58a310156bd09ac536f65aa12122ea1f045c0116 (patch)
tree4e1f2f263e283d907b42aeb43d332acd1df33848
parent17add53388caa3f5b21c8666e1e667fe42639af5 (diff)
downloadetbsa-trackermap-mobile-58a310156bd09ac536f65aa12122ea1f045c0116.tar.gz
etbsa-trackermap-mobile-58a310156bd09ac536f65aa12122ea1f045c0116.tar.bz2
etbsa-trackermap-mobile-58a310156bd09ac536f65aa12122ea1f045c0116.zip
- Disable button when no command is selected.
- Add confirmation for sending command.
-rw-r--r--iosApp/iosApp/Details/Commands/UnitCommandsView.swift11
-rw-r--r--iosApp/iosApp/Details/Commands/UnitCommandsViewModel.swift12
-rw-r--r--iosApp/iosApp/Localizable.strings1
3 files changed, 21 insertions, 3 deletions
diff --git a/iosApp/iosApp/Details/Commands/UnitCommandsView.swift b/iosApp/iosApp/Details/Commands/UnitCommandsView.swift
index 9e4b280..eef3ae4 100644
--- a/iosApp/iosApp/Details/Commands/UnitCommandsView.swift
+++ b/iosApp/iosApp/Details/Commands/UnitCommandsView.swift
@@ -39,10 +39,19 @@ struct UnitCommandsView: View {
}.pickerStyle(InlinePickerStyle())
Button {
- unitCommandsViewModel.sendCommand()
+ unitCommandsViewModel.showConfirmation = true
} label: {
Label("send-command", systemImage: "paperplane")
}
+ .disabled(unitCommandsViewModel.notSelected)
+ .actionSheet(isPresented: $unitCommandsViewModel.showConfirmation) {
+ ActionSheet(title: Text("send-command-confirm"), buttons: [
+ .cancel(),
+ .destructive(Text("send-command")) {
+ unitCommandsViewModel.sendCommand()
+ }
+ ])
+ }
}
}
}
diff --git a/iosApp/iosApp/Details/Commands/UnitCommandsViewModel.swift b/iosApp/iosApp/Details/Commands/UnitCommandsViewModel.swift
index aac82c9..d7298c4 100644
--- a/iosApp/iosApp/Details/Commands/UnitCommandsViewModel.swift
+++ b/iosApp/iosApp/Details/Commands/UnitCommandsViewModel.swift
@@ -25,11 +25,19 @@ class UnitCommandsViewModel: ObservableObject {
@Published var selected: Command?
@Published var selectedId: Int = 0 {
didSet {
- selected = commands.first(where: {
+ if let selected = commands.first(where: {
Int(truncating: $0.id!) == selectedId
- })
+ }) {
+ self.selected = selected
+ notSelected = false
+ } else {
+ self.selected = nil
+ notSelected = true
+ }
}
}
+ @Published var notSelected: Bool = true
+ @Published var showConfirmation: Bool = false
func fetchCommands(id: Int32) {
commandsController.fetchCommands(deviceId: id) { commands, error in
diff --git a/iosApp/iosApp/Localizable.strings b/iosApp/iosApp/Localizable.strings
index 4d1e1f2..76e7bd4 100644
--- a/iosApp/iosApp/Localizable.strings
+++ b/iosApp/iosApp/Localizable.strings
@@ -52,3 +52,4 @@
"maps-url-template" = "https://www.google.com/maps/place/{y},{x}?z=19";
"send-command" = "Send command";
+"send-command-confirm" = "Are you sure you want to send the command?";