aboutsummaryrefslogtreecommitdiff
path: root/iosApp/iosApp/Devices/DevicesView.swift
diff options
context:
space:
mode:
Diffstat (limited to 'iosApp/iosApp/Devices/DevicesView.swift')
-rw-r--r--iosApp/iosApp/Devices/DevicesView.swift39
1 files changed, 12 insertions, 27 deletions
diff --git a/iosApp/iosApp/Devices/DevicesView.swift b/iosApp/iosApp/Devices/DevicesView.swift
index d3a361e..06f1df1 100644
--- a/iosApp/iosApp/Devices/DevicesView.swift
+++ b/iosApp/iosApp/Devices/DevicesView.swift
@@ -18,35 +18,20 @@
import SwiftUI
struct DevicesView: View {
- @StateObject var unitsViewModel: UnitsViewModel
- @State var shouldShowView = false
- @State var action: DeviceRow.Action = .details
- @State var id: Int32?
+ @ObservedObject var devicesViewModel: DevicesViewModel
+
+ init (unitsViewModel: UnitsViewModel) {
+ self._devicesViewModel = ObservedObject(
+ wrappedValue: DevicesViewModel(unitsViewModel: unitsViewModel))
+ }
var body: some View {
- VStack {
- List(unitsViewModel.units, id: \.device.id) { unit in
- DeviceRow(unit: unit, callback: { action in
- self.action = action
- id = unit.device.id
- shouldShowView = true
- })
- .onTapGesture {
- unitsViewModel.searchQuery = ""
- unitsViewModel.isEditing = false
- unitsViewModel.unitsDisplayMode = .map
- unitsViewModel.selectedUnit = unit
- UIApplication.shared.endEditing()
- }
- }
- }
- .sheet(isPresented: $shouldShowView) {
- print("Dismissed")
- } content: {
- if let id = id {
- DetailsView(isPresented: $shouldShowView,
- action: action,
- forId: id)
+ List(devicesViewModel.units, id: \.device.id) { unit in
+ DeviceRow(unit: unit, callback: { action in
+ self.devicesViewModel.show(action: action, for: unit)
+ }).onTapGesture {
+ self.devicesViewModel.select(unit: unit)
+ UIApplication.shared.endEditing()
}
}
}