UnitsLimitsSettingsRootView.swift 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import SwiftUI
  2. import Swinject
  3. extension UnitsLimitsSettings {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @StateObject var state = StateModel()
  7. @State private var shouldDisplayHint: Bool = false
  8. @State var hintDetent = PresentationDetent.large
  9. @State var selectedVerboseHint: AnyView?
  10. @State var hintLabel: String?
  11. @State private var decimalPlaceholder: Decimal = 0.0
  12. @State private var booleanPlaceholder: Bool = false
  13. @Environment(\.colorScheme) var colorScheme
  14. @EnvironmentObject var appIcons: Icons
  15. @Environment(AppState.self) var appState
  16. var body: some View {
  17. List {
  18. Section(
  19. header: Text("Trio Core Setup"),
  20. content: {
  21. Picker("Glucose Units", selection: $state.unitsIndex) {
  22. Text("mg/dL").tag(0)
  23. Text("mmol/L").tag(1)
  24. }
  25. }
  26. ).listRowBackground(Color.chart)
  27. SettingInputSection(
  28. decimalValue: $state.maxIOB,
  29. booleanValue: $booleanPlaceholder,
  30. shouldDisplayHint: $shouldDisplayHint,
  31. selectedVerboseHint: Binding(
  32. get: { selectedVerboseHint },
  33. set: {
  34. selectedVerboseHint = $0.map { AnyView($0) }
  35. hintLabel = NSLocalizedString("Max IOB", comment: "Max IOB")
  36. }
  37. ),
  38. units: state.units,
  39. type: .decimal("maxIOB"),
  40. label: NSLocalizedString("Max IOB", comment: "Max IOB"),
  41. miniHint: "Maximum units of insulin allowed to be active.",
  42. verboseHint:
  43. VStack(alignment: .leading, spacing: 10) {
  44. Text("Default: 0 units").bold()
  45. Text(
  46. "Warning: This must be greater than 0 for any automatic temporary basal rates or SMBs to be given."
  47. ).bold()
  48. Text(
  49. "This is the maximum amount of Insulin On Board (IOB) above profile basal rates from all sources - positive temporary basal rates, manual or meal boluses, and SMBs - that Trio is allowed to accumulate to address an above target glucose."
  50. )
  51. Text(
  52. "If a calculated amount exceeds this limit, the suggested and / or delivered amount will be reduced so that active insulin on board (IOB) will not exceed this safety limit."
  53. )
  54. Text(
  55. "Note: You can still manually bolus above this limit, but the suggested bolus amount will never exceed this in the bolus calculator."
  56. )
  57. }
  58. )
  59. SettingInputSection(
  60. decimalValue: $state.maxBolus,
  61. booleanValue: $booleanPlaceholder,
  62. shouldDisplayHint: $shouldDisplayHint,
  63. selectedVerboseHint: Binding(
  64. get: { selectedVerboseHint },
  65. set: {
  66. selectedVerboseHint = $0.map { AnyView($0) }
  67. hintLabel = "Max Bolus"
  68. }
  69. ),
  70. units: state.units,
  71. type: .decimal("maxBolus"),
  72. label: "Max Bolus",
  73. miniHint: "Largest bolus of insulin allowed.",
  74. verboseHint:
  75. VStack(alignment: .leading, spacing: 10) {
  76. Text("Default: 10 units").bold()
  77. Text(
  78. "This is the maximum bolus allowed to be delivered at one time. This limits manual and automatic bolus."
  79. )
  80. Text("Most set this to their largest meal bolus. Then, adjust if needed.")
  81. Text("If you attempt to request a bolus larger than this, the bolus will not be accepted.")
  82. }
  83. )
  84. SettingInputSection(
  85. decimalValue: $state.maxBasal,
  86. booleanValue: $booleanPlaceholder,
  87. shouldDisplayHint: $shouldDisplayHint,
  88. selectedVerboseHint: Binding(
  89. get: { selectedVerboseHint },
  90. set: {
  91. selectedVerboseHint = $0.map { AnyView($0) }
  92. hintLabel = "Max Basal"
  93. }
  94. ),
  95. units: state.units,
  96. type: .decimal("maxBasal"),
  97. label: "Max Basal",
  98. miniHint: "Largest basal rate allowed.",
  99. verboseHint:
  100. VStack(alignment: .leading, spacing: 10) {
  101. Text("Default: 2 units").bold()
  102. Text(
  103. "This is the maximum basal rate allowed to be set or scheduled. This applies to both automatic and manual basal rates."
  104. )
  105. Text("Note to Medtronic Pump Users: You must also manually set the max basal rate on the pump to this value or higher.")
  106. }
  107. )
  108. SettingInputSection(
  109. decimalValue: $state.maxCOB,
  110. booleanValue: $booleanPlaceholder,
  111. shouldDisplayHint: $shouldDisplayHint,
  112. selectedVerboseHint: Binding(
  113. get: { selectedVerboseHint },
  114. set: {
  115. selectedVerboseHint = $0.map { AnyView($0) }
  116. hintLabel = NSLocalizedString("Max COB", comment: "Max COB")
  117. }
  118. ),
  119. units: state.units,
  120. type: .decimal("maxCOB"),
  121. label: NSLocalizedString("Max COB", comment: "Max COB"),
  122. miniHint: "Maximum Carbs On Board (COB) allowed.",
  123. verboseHint:
  124. VStack(alignment: .leading, spacing: 10) {
  125. Text("Default: 120 grams of carbs").bold()
  126. Text(
  127. "This setting defines the maximum amount of Carbs On Board (COB) at any given time for Trio to use in dosing calculations. If more carbs are entered than allowed by this limit, Trio will cap the current COB in calculations to Max COB and remain at max until all remaining carbs have shown to be absorbed."
  128. )
  129. Text("For example, if Max COB is 120g and you enter a meal containing 150g of carbs, your COB will remain at 120g until the remaining 30g have been absorbed.")
  130. Text("This is an important limit when UAM is ON.")
  131. }
  132. )
  133. }
  134. .listSectionSpacing(sectionSpacing)
  135. .sheet(isPresented: $shouldDisplayHint) {
  136. SettingInputHintView(
  137. hintDetent: $hintDetent,
  138. shouldDisplayHint: $shouldDisplayHint,
  139. hintLabel: hintLabel ?? "",
  140. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  141. sheetTitle: "Help"
  142. )
  143. }
  144. .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
  145. .onAppear(perform: configureView)
  146. .navigationTitle("General")
  147. .navigationBarTitleDisplayMode(.automatic)
  148. .onDisappear {
  149. state.saveIfChanged()
  150. }
  151. }
  152. }
  153. }