diff options
author | Iván Ávalos <avalos@disroot.org> | 2022-02-08 21:48:00 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2022-02-08 21:48:00 -0600 |
commit | b92214eb057fb0cad1fb8f02ad1e1660abe5a19c (patch) | |
tree | b9e455c391bee6b95c884c16241ce8cde597afa3 /iosApp/iosApp/Devices/DevicesView.swift | |
parent | 4f0129a70bafeca1d9e565ba2076213eb183c779 (diff) | |
download | etbsa-trackermap-mobile-b92214eb057fb0cad1fb8f02ad1e1660abe5a19c.tar.gz etbsa-trackermap-mobile-b92214eb057fb0cad1fb8f02ad1e1660abe5a19c.tar.bz2 etbsa-trackermap-mobile-b92214eb057fb0cad1fb8f02ad1e1660abe5a19c.zip |
- Fixed DetailsView.
- Refactored details sheet into UnitsView.
- A lot of logic moved into view models.
- Implemented unit details in UnitMapView.
Diffstat (limited to 'iosApp/iosApp/Devices/DevicesView.swift')
-rw-r--r-- | iosApp/iosApp/Devices/DevicesView.swift | 39 |
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() } } } |