GarminConfigRootView.swift 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import SwiftUI
  2. import Swinject
  3. extension GarminConfig {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @StateObject var state = StateModel()
  7. var body: some View {
  8. Form {
  9. Section {
  10. Button("Select devices") {
  11. state.selectDevices()
  12. }
  13. }
  14. if state.devices.isNotEmpty {
  15. Section(header: Text("Connected devices")) {
  16. List {
  17. ForEach(state.devices, id: \.uuid) { device in
  18. Text(device.friendlyName)
  19. }
  20. .onDelete(perform: onDelete)
  21. }
  22. }
  23. }
  24. }
  25. .onAppear(perform: configureView)
  26. .navigationTitle("Garmin Watch")
  27. .navigationBarTitleDisplayMode(.automatic)
  28. }
  29. private func onDelete(offsets: IndexSet) {
  30. state.devices.remove(atOffsets: offsets)
  31. state.deleteDevice()
  32. }
  33. }
  34. }