WatchConfigGarminView.swift 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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: String?
  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: .top) {
  31. Text(
  32. "Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
  33. )
  34. .font(.footnote)
  35. .foregroundColor(.secondary)
  36. .lineLimit(nil)
  37. Spacer()
  38. Button(
  39. action: {
  40. hintLabel = "Add Device"
  41. selectedVerboseHint = "Add Garmin Device… bla bla bla"
  42. shouldDisplayHint.toggle()
  43. },
  44. label: {
  45. HStack {
  46. Image(systemName: "questionmark.circle")
  47. }
  48. }
  49. ).buttonStyle(BorderlessButtonStyle())
  50. }.padding(.top)
  51. }.padding(.vertical)
  52. }
  53. ).listRowBackground(Color.chart)
  54. if !state.devices.isEmpty {
  55. Section(header: Text("Garmin Watch")) {
  56. List {
  57. ForEach(state.devices, id: \.uuid) { device in
  58. Text(device.friendlyName)
  59. }
  60. .onDelete(perform: onDelete)
  61. }
  62. }.listRowBackground(Color.chart)
  63. }
  64. }
  65. .sheet(isPresented: $shouldDisplayHint) {
  66. SettingInputHintView(
  67. hintDetent: $hintDetent,
  68. shouldDisplayHint: $shouldDisplayHint,
  69. hintLabel: hintLabel ?? "",
  70. hintText: selectedVerboseHint ?? "",
  71. sheetTitle: "Help"
  72. )
  73. }
  74. .navigationTitle("Garmin")
  75. .navigationBarTitleDisplayMode(.automatic)
  76. .scrollContentBackground(.hidden)
  77. .background(appState.trioBackgroundColor(for: colorScheme))
  78. }
  79. }