BolusCalculatorConfigRootView.swift 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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: """
  58. Enabling this feature allows you to create and save preset meals
  59. Default: OFF
  60. """,
  61. verboseHint: VStack {
  62. Text("Default: OFF").bold()
  63. Text("""
  64. Enabling this feature allows you to create and save preset meals.
  65. """)
  66. }
  67. )
  68. SettingInputSection(
  69. decimalValue: $state.overrideFactor,
  70. booleanValue: $booleanPlaceholder,
  71. shouldDisplayHint: $shouldDisplayHint,
  72. selectedVerboseHint: Binding(
  73. get: { selectedVerboseHint },
  74. set: {
  75. selectedVerboseHint = $0.map { AnyView($0) }
  76. hintLabel = "Recommended Bolus Percentage"
  77. }
  78. ),
  79. units: state.units,
  80. type: .decimal("overrideFactor"),
  81. label: "Recommended Bolus Percentage",
  82. miniHint: """
  83. Percentage of the calculated bolus used as your recommended bolus in the bolus calculator
  84. Default: 70%
  85. """,
  86. verboseHint: VStack {
  87. Text("Default: 70%").bold()
  88. Text("""
  89. 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.
  90. Because Trio utilizes SMBs and UAM SMBs to help you reach your target glucose, you'll want this setting to be lower than the full calculated amount (<100%).
  91. """)
  92. Text("It is not advised to set this to 100% if you also have SMBs and/or UAM SMBs enabled.").italic()
  93. },
  94. headerText: "Calculator Configuration"
  95. )
  96. SettingInputSection(
  97. decimalValue: $state.fattyMealFactor,
  98. booleanValue: $state.fattyMeals,
  99. shouldDisplayHint: $shouldDisplayHint,
  100. selectedVerboseHint: Binding(
  101. get: { selectedVerboseHint },
  102. set: {
  103. selectedVerboseHint = $0.map { AnyView($0) }
  104. hintLabel = "Fatty Meal"
  105. }
  106. ),
  107. units: state.units,
  108. type: .conditionalDecimal("fattyMealFactor"),
  109. label: "Enable Fatty Meal",
  110. conditionalLabel: "Fatty Meal Bolus Percentage",
  111. miniHint: """
  112. A "Fatty Meal" option appears in the bolus calculator
  113. Default: OFF
  114. Default %: 70%
  115. """,
  116. verboseHint: VStack(spacing: 10) {
  117. Text("Default: OFF").bold()
  118. Text("Default Percentage: 70%").bold()
  119. Text("""
  120. Enabling this setting adds a "Fatty Meal" option to the bolus calculator. Once this feature is enabled, a percentage setting will appear for you to set. 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.
  121. """)
  122. Text(
  123. "Tip: This setting should be LOWER than your Recommended Bolus Percentage setting to enable the bolus calculator 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."
  124. ).italic()
  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",
  141. conditionalLabel: "Super Bolus Percentage",
  142. miniHint: """
  143. A "Super Bolus" option appears in the bolus calculator
  144. Default: OFF
  145. Default %: 200%
  146. """,
  147. verboseHint: VStack(spacing: 10) {
  148. Text("Default: OFF").bold()
  149. Text("Default Percentage: 200%").bold()
  150. Text("""
  151. Enabling this setting adds a "Super Bolus" option to the bolus calculator. Once this feature is enabled, a percentage setting will appear for you to set. 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.
  152. """)
  153. Text("The Super Bolus is a useful option for sweet or fast meals.")
  154. Text(
  155. "Tip: This setting should be HIGHER than your Recommended Bolus Percentage setting to enable the bolus calculator to give above the calculated amount to address carbs that absorb very quickly. This could be useful when eating sweets."
  156. ).italic()
  157. }
  158. )
  159. }
  160. .sheet(isPresented: $shouldDisplayHint) {
  161. SettingInputHintView(
  162. hintDetent: $hintDetent,
  163. shouldDisplayHint: $shouldDisplayHint,
  164. hintLabel: hintLabel ?? "",
  165. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  166. sheetTitle: "Help"
  167. )
  168. }
  169. .scrollContentBackground(.hidden).background(color)
  170. .onAppear(perform: configureView)
  171. .navigationBarTitle("Bolus Calculator")
  172. .navigationBarTitleDisplayMode(.automatic)
  173. }
  174. }
  175. }