BolusCalculatorConfigRootView.swift 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. import SwiftUI
  2. import Swinject
  3. extension BolusCalculatorConfig {
  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. var color: LinearGradient {
  15. colorScheme == .dark ? LinearGradient(
  16. gradient: Gradient(colors: [
  17. Color.bgDarkBlue,
  18. Color.bgDarkerDarkBlue
  19. ]),
  20. startPoint: .top,
  21. endPoint: .bottom
  22. )
  23. :
  24. LinearGradient(
  25. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  26. startPoint: .top,
  27. endPoint: .bottom
  28. )
  29. }
  30. private var conversionFormatter: NumberFormatter {
  31. let formatter = NumberFormatter()
  32. formatter.numberStyle = .decimal
  33. formatter.maximumFractionDigits = 1
  34. return formatter
  35. }
  36. private var formatter: NumberFormatter {
  37. let formatter = NumberFormatter()
  38. formatter.numberStyle = .decimal
  39. return formatter
  40. }
  41. var body: some View {
  42. Form {
  43. SettingInputSection(
  44. decimalValue: $decimalPlaceholder,
  45. booleanValue: $state.displayPresets,
  46. shouldDisplayHint: $shouldDisplayHint,
  47. selectedVerboseHint: Binding(
  48. get: { selectedVerboseHint },
  49. set: {
  50. selectedVerboseHint = $0.map { AnyView($0) }
  51. hintLabel = "Display Meal Presets"
  52. }
  53. ),
  54. units: state.units,
  55. type: .boolean,
  56. label: "Display Meal Presets",
  57. miniHint: "Allows you to create and save preset meals",
  58. verboseHint: VStack(spacing: 10) {
  59. Text("Default: OFF").bold()
  60. Text("Enabling this feature allows you to create and save preset meals.")
  61. }
  62. )
  63. SettingInputSection(
  64. decimalValue: $state.overrideFactor,
  65. booleanValue: $booleanPlaceholder,
  66. shouldDisplayHint: $shouldDisplayHint,
  67. selectedVerboseHint: Binding(
  68. get: { selectedVerboseHint },
  69. set: {
  70. selectedVerboseHint = $0.map { AnyView($0) }
  71. hintLabel = "Recommended Bolus Percentage"
  72. }
  73. ),
  74. units: state.units,
  75. type: .decimal("overrideFactor"),
  76. label: "Recommended Bolus Percentage",
  77. miniHint: "Percent of bolus used in bolus calculator",
  78. verboseHint: VStack(spacing: 10) {
  79. Text("Default: 70%").bold()
  80. VStack(alignment: .leading, spacing: 10) {
  81. Text(
  82. "Recommended Bolus Percentage is a safety feature built into Trio. Trio first calculates an insulin required value, which is the full dosage. That dosage is then multiplied by your Recommended Bolus Percentage to display your suggested insulin dose in the bolus calculator."
  83. )
  84. Text(
  85. "Because Trio utilizes SMBs and UAM SMBs to help you reach your target glucose, this is initially set to below the full calculated amount (<100%) because other AID systems do not bolus for COB the same way Trio does. When SMBs and UAM SMBs are enabled, you may find your current CR results in lows and needs to be increased before you increase this setting closer to or at 100%."
  86. )
  87. Text(
  88. "Tip: If you are a new Trio user, it is not advised to set this to 100% until you have verified that your core settings (basal rates, ISF, and CR) do not need adjusting."
  89. )
  90. }
  91. },
  92. headerText: "Calculator Configuration"
  93. )
  94. SettingInputSection(
  95. decimalValue: $state.fattyMealFactor,
  96. booleanValue: $state.fattyMeals,
  97. shouldDisplayHint: $shouldDisplayHint,
  98. selectedVerboseHint: Binding(
  99. get: { selectedVerboseHint },
  100. set: {
  101. selectedVerboseHint = $0.map { AnyView($0) }
  102. hintLabel = "Fatty Meal"
  103. }
  104. ),
  105. units: state.units,
  106. type: .conditionalDecimal("fattyMealFactor"),
  107. label: "Enable Fatty Meal Option",
  108. conditionalLabel: "Fatty Meal Bolus Percentage",
  109. miniHint: "\"Fatty Meal\" option appears in the bolus calculator",
  110. verboseHint: VStack(spacing: 10) {
  111. Text("Default: OFF").bold()
  112. Text("Default Percent: 70%").bold()
  113. VStack(alignment: .leading, spacing: 10) {
  114. Text("Do not enable this feature until you have optimized your CR (carb ratio) setting.").bold()
  115. Text(
  116. "Enabling this setting adds a \"Fatty Meal\" option to the bolus calculator. Once this feature is enabled, a percentage setting will appear below this for you to select."
  117. )
  118. Text(
  119. "When you use a Fatty Meal Bolus, the percentage you select for this setting will replace the Recommended Bolus Percentage setting used in that bolus calculation."
  120. )
  121. Text(
  122. "Tip: This setting should be ↓LOWER↓ than your Recommended Bolus Percentage setting to enable the bolus calculator the ability to give less than the calculated amount to prevent lows due to carbs absorbing very slowly. This could be useful when eating meals like pizza."
  123. )
  124. }
  125. }
  126. )
  127. SettingInputSection(
  128. decimalValue: $state.sweetMealFactor,
  129. booleanValue: $state.sweetMeals,
  130. shouldDisplayHint: $shouldDisplayHint,
  131. selectedVerboseHint: Binding(
  132. get: { selectedVerboseHint },
  133. set: {
  134. selectedVerboseHint = $0.map { AnyView($0) }
  135. hintLabel = "Super Bolus"
  136. }
  137. ),
  138. units: state.units,
  139. type: .conditionalDecimal("sweetMealFactor"),
  140. label: "Enable Super Bolus Option",
  141. conditionalLabel: "Super Bolus Percentage",
  142. miniHint: "\"Super Bolus\" option appears in the bolus calculator",
  143. verboseHint: VStack(spacing: 10) {
  144. Text("Default: OFF").bold()
  145. Text("Default Percent: 200%").bold()
  146. VStack(alignment: .leading, spacing: 10) {
  147. Text("Do not enable this feature until you have optimized your CR (carb ratio) setting.").bold()
  148. Text(
  149. "Enabling this setting adds a \"Super Bolus\" option to the bolus calculator. Once this feature is enabled, a percentage setting will appear below this for you to select."
  150. )
  151. Text(
  152. "When you use a Super Bolus, the percentage you select for this setting will replace the Recommended Bolus Percentage setting used in that bolus calculation."
  153. )
  154. Text("The Super Bolus is a useful option for sweet or fast meals.")
  155. Text(
  156. "Tip: This setting should be ↑HIGHER↑ than your Recommended Bolus Percentage setting to enable the bolus calculator the ability to give above the calculated amount to address carbs that absorb very quickly. This could be useful when eating sweets."
  157. )
  158. }
  159. }
  160. )
  161. }
  162. .sheet(isPresented: $shouldDisplayHint) {
  163. SettingInputHintView(
  164. hintDetent: $hintDetent,
  165. shouldDisplayHint: $shouldDisplayHint,
  166. hintLabel: hintLabel ?? "",
  167. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  168. sheetTitle: "Help"
  169. )
  170. }
  171. .scrollContentBackground(.hidden).background(color)
  172. .onAppear(perform: configureView)
  173. .navigationBarTitle("Bolus Calculator")
  174. .navigationBarTitleDisplayMode(.automatic)
  175. }
  176. }
  177. }