WatchConfigGarminView.swift 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import SwiftUI
  2. struct WatchConfigGarminView: View {
  3. @ObservedObject var state: WatchConfig.StateModel
  4. @State private var shouldDisplayHint: Bool = false
  5. @State var hintDetent = PresentationDetent.large
  6. @State var selectedVerboseHint: AnyView?
  7. @State var hintLabel: String?
  8. @State private var decimalPlaceholder: Decimal = 0.0
  9. @State private var booleanPlaceholder: Bool = false
  10. @Environment(\.colorScheme) var colorScheme
  11. @Environment(AppState.self) var appState
  12. private func onDelete(offsets: IndexSet) {
  13. state.devices.remove(atOffsets: offsets)
  14. state.deleteGarminDevice()
  15. }
  16. var body: some View {
  17. Form {
  18. Section(
  19. header: Text("Garmin Configuration"),
  20. content:
  21. {
  22. VStack {
  23. Button {
  24. state.selectGarminDevices()
  25. } label: {
  26. Text("Add Device")
  27. .font(.title3) }
  28. .frame(maxWidth: .infinity, alignment: .center)
  29. .buttonStyle(.bordered)
  30. HStack(alignment: .center) {
  31. Text(
  32. "Add a Garmin Device to Trio."
  33. )
  34. .font(.footnote)
  35. .foregroundColor(.secondary)
  36. .lineLimit(nil)
  37. Spacer()
  38. Button(
  39. action: {
  40. shouldDisplayHint.toggle()
  41. },
  42. label: {
  43. HStack {
  44. Image(systemName: "questionmark.circle")
  45. }
  46. }
  47. ).buttonStyle(BorderlessButtonStyle())
  48. }.padding(.top)
  49. }.padding(.vertical)
  50. }
  51. ).listRowBackground(Color.chart)
  52. if !state.devices.isEmpty {
  53. Section(
  54. header: Text("Garmin Watch"),
  55. content: {
  56. List {
  57. ForEach(state.devices, id: \.uuid) { device in
  58. Text(device.friendlyName)
  59. }
  60. .onDelete(perform: onDelete)
  61. }
  62. }
  63. ).listRowBackground(Color.chart)
  64. }
  65. }
  66. .listSectionSpacing(sectionSpacing)
  67. .sheet(isPresented: $shouldDisplayHint) {
  68. SettingInputHintView(
  69. hintDetent: $hintDetent,
  70. shouldDisplayHint: $shouldDisplayHint,
  71. hintLabel: "Add Device",
  72. hintText: Text(
  73. "Add Garmin Device to Trio. Please look at the docs to see which devices are supported."
  74. ),
  75. sheetTitle: "Help"
  76. )
  77. }
  78. .navigationTitle("Garmin")
  79. .navigationBarTitleDisplayMode(.automatic)
  80. .scrollContentBackground(.hidden)
  81. .background(appState.trioBackgroundColor(for: colorScheme))
  82. }
  83. }