PumpConfigRootView.swift 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import SwiftUI
  2. import Swinject
  3. extension PumpConfig {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. let displayClose: Bool
  7. @StateObject var state = StateModel()
  8. @State private var shouldDisplayHint: Bool = false
  9. @State var hintDetent = PresentationDetent.large
  10. @State var selectedVerboseHint: String?
  11. @State var hintLabel: String?
  12. @State private var decimalPlaceholder: Decimal = 0.0
  13. @State private var booleanPlaceholder: Bool = false
  14. @State var showPumpSelection: Bool = false
  15. @Environment(\.colorScheme) var colorScheme
  16. @Environment(AppState.self) var appState
  17. var body: some View {
  18. NavigationView {
  19. Form {
  20. Section(
  21. header: Text("Pump Integration to Trio"),
  22. content: {
  23. if let pumpState = state.pumpState {
  24. Button {
  25. state.setupPump = true
  26. } label: {
  27. HStack {
  28. Image(uiImage: pumpState.image ?? UIImage()).padding()
  29. Text(pumpState.name)
  30. }
  31. }
  32. if state.alertNotAck {
  33. Spacer()
  34. Button("Acknowledge all alerts") { state.ack() }
  35. }
  36. } else {
  37. VStack {
  38. Button {
  39. showPumpSelection.toggle()
  40. } label: {
  41. Text("Add Pump")
  42. .font(.title3) }
  43. .frame(maxWidth: .infinity, alignment: .center)
  44. .buttonStyle(.bordered)
  45. HStack(alignment: .top) {
  46. Text(
  47. "Pair a compatible pump with Trio. See details for available devices."
  48. )
  49. .font(.footnote)
  50. .foregroundColor(.secondary)
  51. .lineLimit(nil)
  52. Spacer()
  53. Button(
  54. action: {
  55. hintLabel = "Pump Pairing to Trio"
  56. selectedVerboseHint =
  57. "Explanation… limitation… etc."
  58. shouldDisplayHint.toggle()
  59. },
  60. label: {
  61. HStack {
  62. Image(systemName: "questionmark.circle")
  63. }
  64. }
  65. ).buttonStyle(BorderlessButtonStyle())
  66. }.padding(.top)
  67. }.padding(.vertical)
  68. }
  69. }
  70. )
  71. .padding(.top)
  72. .listRowBackground(Color.chart)
  73. }
  74. .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
  75. .onAppear(perform: configureView)
  76. .navigationTitle("Insulin Pump")
  77. .navigationBarTitleDisplayMode(.automatic)
  78. .navigationBarItems(leading: displayClose ? Button("Close", action: state.hideModal) : nil)
  79. .sheet(isPresented: $state.setupPump) {
  80. if let pumpManager = state.provider.apsManager.pumpManager {
  81. PumpSettingsView(
  82. pumpManager: pumpManager,
  83. bluetoothManager: state.provider.apsManager.bluetoothManager!,
  84. completionDelegate: state,
  85. setupDelegate: state
  86. )
  87. } else {
  88. PumpSetupView(
  89. pumpType: state.setupPumpType,
  90. pumpInitialSettings: state.initialSettings,
  91. bluetoothManager: state.provider.apsManager.bluetoothManager!,
  92. completionDelegate: state,
  93. setupDelegate: state
  94. )
  95. }
  96. }
  97. .sheet(isPresented: $shouldDisplayHint) {
  98. SettingInputHintView(
  99. hintDetent: $hintDetent,
  100. shouldDisplayHint: $shouldDisplayHint,
  101. hintLabel: hintLabel ?? "",
  102. hintText: selectedVerboseHint ?? "",
  103. sheetTitle: "Help"
  104. )
  105. }
  106. .confirmationDialog("Pump Model", isPresented: $showPumpSelection) {
  107. Button("Medtronic") { state.addPump(.minimed) }
  108. Button("Omnipod Eros") { state.addPump(.omnipod) }
  109. Button("Omnipod Dash") { state.addPump(.omnipodBLE) }
  110. Button("Dana(RS/-i)") { state.addPump(.dana) }
  111. Button("Pump Simulator") { state.addPump(.simulator) }
  112. } message: { Text("Select Pump Model") }
  113. }
  114. }
  115. }
  116. }