diff options
Diffstat (limited to 'iosApp')
-rw-r--r-- | iosApp/iosApp/Details/Commands/UnitCommandsView.swift | 11 | ||||
-rw-r--r-- | iosApp/iosApp/Details/Commands/UnitCommandsViewModel.swift | 12 | ||||
-rw-r--r-- | iosApp/iosApp/Localizable.strings | 1 |
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?"; |