/** * TrackerMap * Copyright (C) 2021-2022 Iván Ávalos , Henoch Ojeda * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ import SwiftUI import shared struct DetailsView: View { @ObservedObject var detailsViewModel = DetailsViewModel() @Binding var isPresented: Bool @State var action: DeviceRow.Action var id: Int32? init(isPresented: Binding, action: DeviceRow.Action, forId id: Int32?) { self._isPresented = isPresented self.action = action self.id = id if let id = id { self.detailsViewModel.fetchUnit(id: id) } } var body: some View { NavigationView { VStack { if id != nil { if let unit = detailsViewModel.unit { switch action { case .details: UnitInformationView(unit: unit) case .reports: UnitReportsView(unit: unit) case .commands: UnitCommandsView(unit: unit) } } else { LoadingView() } } } .navigationBarTitleView( Picker(selection: $action) { Text("details").tag(DeviceRow.Action.details) Text("reports").tag(DeviceRow.Action.reports) Text("commands").tag(DeviceRow.Action.commands) } label: { EmptyView() }.pickerStyle(SegmentedPickerStyle()) ) .navigationTitle(detailsViewModel.unit?.device.name ?? NSLocalizedString("loading", comment: "")) .navigationBarTitleDisplayMode(.large) .toolbar { ToolbarItem(placement: .navigationBarLeading) { if let category = detailsViewModel.unit?.device.category { let type = Marker.companion .categoryToMarkerType(category: category) Image(MarkerTransformations.markerTypeToImageName(markerType: type)) } else { EmptyView() } } ToolbarItem(placement: .navigationBarTrailing) { Button { isPresented = false } label: { Text("done").bold() } } } } } }