/** * 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 { @Binding var isPresented: Bool @State var action: DeviceRow.Action var unit: UnitInformation? init(isPresented: Binding, action: DeviceRow.Action, for unit: UnitInformation?) { self._isPresented = isPresented self.action = action self.unit = unit } var body: some View { NavigationView { VStack { if let unit = unit { switch action { case .details: UnitInformationView(unit: unit) case .reports: UnitReportsView(unit: unit) case .commands: UnitCommandsView(unit: unit) default: EmptyView() } } 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(unit?.device.name ?? NSLocalizedString("loading", comment: "")) .navigationBarTitleDisplayMode(.large) .toolbar { ToolbarItem(placement: .navigationBarLeading) { if let category = unit?.device.category { let type = Marker.companion .categoryToMarkerType(category: category) Image(MarkerTransformations.markerTypeToImageName(markerType: type)) .sizeToFit() } else { EmptyView() } } ToolbarItem(placement: .navigationBarTrailing) { Button { isPresented = false } label: { Text("done").bold() } } } } } }