BolusCalculatorConfigRootView.swift 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. @Environment(AppState.self) var appState
  15. private var conversionFormatter: NumberFormatter {
  16. let formatter = NumberFormatter()
  17. formatter.numberStyle = .decimal
  18. formatter.maximumFractionDigits = 1
  19. return formatter
  20. }
  21. private var formatter: NumberFormatter {
  22. let formatter = NumberFormatter()
  23. formatter.numberStyle = .decimal
  24. return formatter
  25. }
  26. var body: some View {
  27. List {
  28. SettingInputSection(
  29. decimalValue: $decimalPlaceholder,
  30. booleanValue: $state.displayPresets,
  31. shouldDisplayHint: $shouldDisplayHint,
  32. selectedVerboseHint: Binding(
  33. get: { selectedVerboseHint },
  34. set: {
  35. selectedVerboseHint = $0.map { AnyView($0) }
  36. hintLabel = "Display Meal Presets"
  37. }
  38. ),
  39. units: state.units,
  40. type: .boolean,
  41. label: "Display Meal Presets",
  42. miniHint: "Allows you to create and save preset meals.",
  43. verboseHint: VStack(alignment: .leading, spacing: 10) {
  44. Text("Default: ON").bold()
  45. Text("Enabling this feature allows you to create and save preset meals.")
  46. }
  47. )
  48. SettingInputSection(
  49. decimalValue: $state.overrideFactor,
  50. booleanValue: $booleanPlaceholder,
  51. shouldDisplayHint: $shouldDisplayHint,
  52. selectedVerboseHint: Binding(
  53. get: { selectedVerboseHint },
  54. set: {
  55. selectedVerboseHint = $0.map { AnyView($0) }
  56. hintLabel = "Recommended Bolus Percentage"
  57. }
  58. ),
  59. units: state.units,
  60. type: .decimal("overrideFactor"),
  61. label: "Recommended Bolus Percentage",
  62. miniHint: "Percentage of bolus used in bolus calculator.",
  63. verboseHint:
  64. VStack(alignment: .leading, spacing: 10) {
  65. Text("Default: 80%").bold()
  66. Text(
  67. "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."
  68. )
  69. Text(
  70. "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%."
  71. )
  72. Text(
  73. "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."
  74. )
  75. },
  76. headerText: "Calculator Configuration"
  77. )
  78. SettingInputSection(
  79. decimalValue: $state.fattyMealFactor,
  80. booleanValue: $state.fattyMeals,
  81. shouldDisplayHint: $shouldDisplayHint,
  82. selectedVerboseHint: Binding(
  83. get: { selectedVerboseHint },
  84. set: {
  85. selectedVerboseHint = $0.map { AnyView($0) }
  86. hintLabel = "Fatty Meal"
  87. }
  88. ),
  89. units: state.units,
  90. type: .conditionalDecimal("fattyMealFactor"),
  91. label: "Enable Fatty Meal Option",
  92. conditionalLabel: "Fatty Meal Bolus Percentage",
  93. miniHint: "Adds a \"Fatty Meal\" option to the bolus calculator.",
  94. verboseHint:
  95. VStack(alignment: .leading, spacing: 10) {
  96. Text("Default: OFF").bold()
  97. Text("Default Percent: 70%").bold()
  98. Text("Do not enable this feature until you have optimized your CR (carb ratio) setting.").bold()
  99. Text(
  100. "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 select."
  101. )
  102. Text(
  103. "When \"Fatty Meal\" is selected in the bolus calculator, the recommended bolus will be multiplied by the \"Fatty Meal Bolus Percentage\" as well as the \"Recommended Bolus Percentage\"."
  104. )
  105. Text(
  106. "If you have a \"Recommended Bolus Percentage\" of 80%, and a \"Fatty Meal Bolus Percentage\" of 70%, your recommended bolus will be multiplied by: (80 × 70) ÷ 100 = 56%."
  107. )
  108. Text("This could be useful for slow absorbing meals like pizza.")
  109. }
  110. )
  111. SettingInputSection(
  112. decimalValue: $state.sweetMealFactor,
  113. booleanValue: $state.sweetMeals,
  114. shouldDisplayHint: $shouldDisplayHint,
  115. selectedVerboseHint: Binding(
  116. get: { selectedVerboseHint },
  117. set: {
  118. selectedVerboseHint = $0.map { AnyView($0) }
  119. hintLabel = "Super Bolus"
  120. }
  121. ),
  122. units: state.units,
  123. type: .conditionalDecimal("sweetMealFactor"),
  124. label: "Enable Super Bolus Option",
  125. conditionalLabel: "Super Bolus Percentage",
  126. miniHint: "Adds a \"Super Bolus\" option to the bolus calculator.",
  127. verboseHint:
  128. VStack(alignment: .leading, spacing: 10) {
  129. Text("Default: OFF").bold()
  130. Text("Default Percent: 200%").bold()
  131. Text("Do not enable this feature until you have optimized your CR (carb ratio) setting.").bold()
  132. Text(
  133. "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 select."
  134. )
  135. Text(
  136. "When \"Super Bolus\" is selected in the bolus calculator, your current basal rate multiplied by \"Super Bolus Percentage\" will be added to your bolus recommendation."
  137. )
  138. Text(
  139. "If your current basal rate is 0.8 U/hr and \"Super Bolus Percentage\" is set to 200%: 0.8 × (200 ÷ 100) = 1.6 units will be added to your bolus recommendation."
  140. )
  141. Text("This could be useful for fast absorbing meals like sugary cereal.")
  142. }
  143. )
  144. }
  145. .listSectionSpacing(sectionSpacing)
  146. .sheet(isPresented: $shouldDisplayHint) {
  147. SettingInputHintView(
  148. hintDetent: $hintDetent,
  149. shouldDisplayHint: $shouldDisplayHint,
  150. hintLabel: hintLabel ?? "",
  151. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  152. sheetTitle: "Help"
  153. )
  154. }
  155. .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
  156. .onAppear(perform: configureView)
  157. .navigationBarTitle("Bolus Calculator")
  158. .navigationBarTitleDisplayMode(.automatic)
  159. }
  160. }
  161. }