OnboardingView+Util.swift 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. import SwiftUI
  2. /// Represents the navigation direction in the onboarding flow
  3. enum OnboardingNavigationDirection {
  4. case forward
  5. case backward
  6. }
  7. /// Represents the different steps in the onboarding process.
  8. enum OnboardingStep: Int, CaseIterable, Identifiable, Equatable {
  9. case welcome
  10. case startupGuide
  11. case overview
  12. case diagnostics
  13. case nightscout
  14. case unitSelection
  15. case glucoseTarget
  16. case basalRates
  17. case carbRatio
  18. case insulinSensitivity
  19. case deliveryLimits
  20. case algorithmSettings
  21. case autosensSettings
  22. case smbSettings
  23. case targetBehavior
  24. case notifications
  25. case bluetooth
  26. case completed
  27. var id: Int { rawValue }
  28. var hasSubsteps: Bool {
  29. self == .deliveryLimits
  30. }
  31. var substeps: [DeliveryLimitSubstep] {
  32. guard hasSubsteps else { return [] }
  33. return DeliveryLimitSubstep.allCases
  34. }
  35. /// The title to display for this onboarding step.
  36. var title: String {
  37. switch self {
  38. case .welcome:
  39. return String(localized: "Welcome to Trio")
  40. case .startupGuide:
  41. return String(localized: "Startup Guide")
  42. case .overview:
  43. return String(localized: "Overview")
  44. case .diagnostics:
  45. return String(localized: "Diagnostics")
  46. case .nightscout:
  47. return String(localized: "Nightscout")
  48. case .unitSelection:
  49. return String(localized: "Units & Pump")
  50. case .glucoseTarget:
  51. return String(localized: "Glucose Targets")
  52. case .basalRates:
  53. return String(localized: "Basal Rates")
  54. case .carbRatio:
  55. return String(localized: "Carb Ratios")
  56. case .insulinSensitivity:
  57. return String(localized: "Insulin Sensitivities")
  58. case .deliveryLimits:
  59. return String(localized: "Delivery Limits")
  60. case .algorithmSettings:
  61. return String(localized: "Algorithm Settings")
  62. case .autosensSettings:
  63. return String(localized: "Autosens")
  64. case .smbSettings:
  65. return String(localized: "Super Micro Bolus")
  66. case .targetBehavior:
  67. return String(localized: "Target Behavior")
  68. case .notifications:
  69. return String(localized: "Notifications")
  70. case .bluetooth:
  71. return String(localized: "Bluetooth")
  72. case .completed:
  73. return String(localized: "All Set!")
  74. }
  75. }
  76. /// A detailed description of what this onboarding step is about.
  77. var description: String {
  78. switch self {
  79. case .welcome:
  80. return String(
  81. localized: "Trio is a powerful app that helps you manage your diabetes. Let's get started by setting up a few important parameters that will help Trio work effectively for you."
  82. )
  83. case .startupGuide:
  84. return String(
  85. localized: "Trio comes with a helpful Startup Guide. We recommend opening it now and following along as you go — side by side."
  86. )
  87. case .overview:
  88. return String(
  89. localized: "Trio's Onboarding takes about 15-30 minutes to complete. We'll guide you through each step."
  90. )
  91. case .diagnostics:
  92. return String(
  93. localized: "By default, Trio collects crash reports and other anonymized data related to errors, exceptions, and overall app performance."
  94. )
  95. case .nightscout:
  96. return String(
  97. localized: "Nightscout is a cloud-based platform that allows you to store your diabetes data. It's often used by caregivers to remotely monitor what Trio is doing."
  98. )
  99. case .unitSelection:
  100. return String(
  101. localized: "Before you can begin with configuring your therapy settings, Trio needs to know which units you use for your glucose and insulin measurements (based on your pump model)."
  102. )
  103. case .glucoseTarget:
  104. return String(
  105. localized: "Your glucose target is the blood glucose level you aim to maintain. Trio will use this to calculate insulin doses and provide recommendations."
  106. )
  107. case .basalRates:
  108. return String(
  109. localized: "Your basal profile represents the amount of background insulin you need throughout the day. This helps Trio calculate your insulin needs."
  110. )
  111. case .carbRatio:
  112. return String(
  113. localized: "Your carb ratio tells how many grams of carbohydrates one unit of insulin will cover. This is essential for accurate meal bolus calculations."
  114. )
  115. case .insulinSensitivity:
  116. return String(
  117. localized: "Your insulin sensitivity factor (ISF) indicates how much one unit of insulin will lower your blood glucose. This helps calculate correction boluses."
  118. )
  119. case .deliveryLimits:
  120. return String(
  121. localized: "Trio includes several safety limits for insulin delivery and carbohydrate entry, helping ensure a safe and effective experience."
  122. )
  123. case .algorithmSettings:
  124. return String(
  125. localized: "Trio includes several algorithm settings that allow you to customize the oref algorithm behavior to suit your specific needs."
  126. )
  127. case .autosensSettings:
  128. return String(
  129. localized: "Auto-sensitivity (Autosens) adjusts insulin delivery based on observed sensitivity or resistance."
  130. )
  131. case .smbSettings:
  132. return String(
  133. localized: "SMB (Super Micro Bolus) is an oref algorithm feature that delivers small frequent boluses instead of temporary basals for faster glucose control."
  134. )
  135. case .targetBehavior:
  136. return String(
  137. localized: "Target Behavior allows you to adjust how temporary targets influence ISF, basal, and auto-targeting based on sensitivity or resistance."
  138. )
  139. case .notifications:
  140. return String(localized: " Allow Trio to send you Notifications. These may include alerts, sounds, and icon badges.")
  141. case .bluetooth:
  142. return String(localized: "Allow Trio to use Bluetooth to communicate with your insulin pump and CGM.")
  143. case .completed:
  144. return String(
  145. localized: "Great job! You've completed the initial setup of Trio. You can always adjust these settings later in the app."
  146. )
  147. }
  148. }
  149. /// The system icon name associated with this step.
  150. var iconName: String {
  151. switch self {
  152. case .welcome:
  153. return "hand.wave.fill"
  154. case .startupGuide:
  155. return "list.bullet.clipboard.fill"
  156. case .overview:
  157. return "checklist.unchecked"
  158. case .diagnostics:
  159. return "waveform.badge.magnifyingglass"
  160. case .nightscout:
  161. return "owl"
  162. case .unitSelection:
  163. return "numbers.rectangle"
  164. case .glucoseTarget:
  165. return "target"
  166. case .basalRates:
  167. return "chart.xyaxis.line"
  168. case .carbRatio:
  169. return "fork.knife"
  170. case .insulinSensitivity:
  171. return "drop.fill"
  172. case .deliveryLimits:
  173. return "slider.horizontal.3"
  174. case .algorithmSettings:
  175. return "gearshape.2.fill"
  176. case .autosensSettings:
  177. return "dial.low.fill"
  178. case .smbSettings:
  179. return "bolt.fill"
  180. case .targetBehavior:
  181. return "gyroscope"
  182. case .notifications:
  183. return "bell.badge.fill"
  184. case .bluetooth:
  185. return "logo.bluetooth.capsule.portrait.fill"
  186. case .completed:
  187. return "checkmark.circle.fill"
  188. }
  189. }
  190. /// Returns the next step in the onboarding process, or nil if this is the last step.
  191. var next: OnboardingStep? {
  192. let allCases = OnboardingStep.allCases
  193. let currentIndex = allCases.firstIndex(of: self) ?? 0
  194. let nextIndex = currentIndex + 1
  195. return nextIndex < allCases.count ? allCases[nextIndex] : nil
  196. }
  197. /// Returns the previous step in the onboarding process, or nil if this is the first step.
  198. var previous: OnboardingStep? {
  199. let allCases = OnboardingStep.allCases
  200. let currentIndex = allCases.firstIndex(of: self) ?? 0
  201. let previousIndex = currentIndex - 1
  202. return previousIndex >= 0 ? allCases[previousIndex] : nil
  203. }
  204. /// The accent color to use for this step.
  205. var accentColor: Color {
  206. switch self {
  207. case .algorithmSettings,
  208. .autosensSettings,
  209. .bluetooth,
  210. .completed,
  211. .deliveryLimits,
  212. .diagnostics,
  213. .nightscout,
  214. .notifications,
  215. .overview,
  216. .smbSettings,
  217. .startupGuide,
  218. .targetBehavior,
  219. .unitSelection,
  220. .welcome:
  221. return Color.blue
  222. case .glucoseTarget:
  223. return Color.green
  224. case .basalRates:
  225. return Color.purple
  226. case .carbRatio:
  227. return Color.orange
  228. case .insulinSensitivity:
  229. return Color.red
  230. }
  231. }
  232. }
  233. var nonInfoOnboardingSteps: [OnboardingStep] { OnboardingStep.allCases
  234. .filter { $0 != .welcome && $0 != .startupGuide && $0 != .overview && $0 != .completed }
  235. }
  236. enum DeliveryLimitSubstep: Int, CaseIterable, Identifiable {
  237. case maxIOB
  238. case maxBolus
  239. case maxBasal
  240. case maxCOB
  241. case minimumSafetyThreshold
  242. var id: Int { rawValue }
  243. var title: String {
  244. switch self {
  245. case .maxIOB: return String(localized: "Max IOB", comment: "Max IOB")
  246. case .maxBolus: return String(localized: "Max Bolus")
  247. case .maxBasal: return String(localized: "Max Basal Rate")
  248. case .maxCOB: return String(localized: "Max COB", comment: "Max COB")
  249. case .minimumSafetyThreshold: return String(localized: "Minimum Safety Threshold")
  250. }
  251. }
  252. var hint: String {
  253. switch self {
  254. case .maxIOB: return String(localized: "Maximum units of insulin allowed to be active.")
  255. case .maxBolus: return String(localized: "Largest bolus of insulin allowed.")
  256. case .maxBasal: return String(localized: "Largest basal rate allowed.")
  257. case .maxCOB: return String(localized: "Maximum Carbs On Board (COB) allowed.")
  258. case .minimumSafetyThreshold: return String(localized: "Increase the safety threshold used to suspend insulin delivery.")
  259. }
  260. }
  261. func description(units: GlucoseUnits) -> any View {
  262. switch self {
  263. case .maxIOB:
  264. return VStack(alignment: .leading, spacing: 8) {
  265. Text(
  266. "Note: This setting must be greater than 0 for any automatic insulin dosing by Trio."
  267. ).bold().foregroundStyle(Color.primary)
  268. Text(
  269. "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."
  270. )
  271. Text(
  272. "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."
  273. )
  274. Text(
  275. "Note: You can still manually bolus above this limit, but the suggested bolus amount will never exceed this in the bolus calculator."
  276. )
  277. }
  278. case .maxBolus:
  279. return VStack(alignment: .leading, spacing: 8) {
  280. Text(
  281. "This is the maximum bolus allowed to be delivered at one time. This limits manual and automatic bolus."
  282. )
  283. Text("Most set this to their largest meal bolus. Then, adjust if needed.")
  284. Text("If you attempt to request a bolus larger than this, the bolus will not be accepted.")
  285. }
  286. case .maxBasal:
  287. return VStack(alignment: .leading, spacing: 8) {
  288. Text(
  289. "This is the maximum basal rate allowed to be set or scheduled. This applies to both automatic and manual basal rates."
  290. )
  291. Text(
  292. "Note to Medtronic Pump Users: You must also manually set the max basal rate on the pump to this value or higher."
  293. )
  294. }
  295. case .maxCOB:
  296. return VStack(alignment: .leading, spacing: 8) {
  297. Text(
  298. "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."
  299. )
  300. Text(
  301. "For example, if Max COB is 120 g and you enter a meal containing 150 g of carbs, your COB will remain at 120 g until the remaining 30 g have been absorbed."
  302. )
  303. Text("This is an important limit when UAM is ON.")
  304. }
  305. case .minimumSafetyThreshold:
  306. return VStack(alignment: .leading, spacing: 8) {
  307. Text("Default: Set by Algorithm").bold()
  308. Text(
  309. "Minimum Threshold Setting is, by default, determined by your set Glucose Target. This threshold automatically suspends insulin delivery if your glucose levels are forecasted to fall below this value. It’s designed to protect against hypoglycemia, particularly during sleep or other vulnerable times."
  310. )
  311. Text(
  312. "Trio will use the larger of the default setting calculation below and the value entered here."
  313. )
  314. VStack(alignment: .leading, spacing: 8) {
  315. VStack(alignment: .leading, spacing: 5) {
  316. Text("The default setting is based on this calculation:").bold()
  317. Text("TargetGlucose - 0.5 × (TargetGlucose - 40)")
  318. }
  319. VStack(alignment: .leading, spacing: 5) {
  320. Text(
  321. "If your glucose target is \(units == .mgdL ? "110" : 110.formattedAsMmolL) \(units.rawValue), Trio will use a safety threshold of \(units == .mgdL ? "75" : 75.formattedAsMmolL) \(units.rawValue), unless you set Minimum Safety Threshold to something > \(units == .mgdL ? "75" : 75.formattedAsMmolL) \(units.rawValue)."
  322. )
  323. Text(
  324. "\(units == .mgdL ? "110" : 110.formattedAsMmolL) - 0.5 × (\(units == .mgdL ? "110" : 110.formattedAsMmolL) - \(units == .mgdL ? "40" : 40.formattedAsMmolL)) = \(units == .mgdL ? "75" : 75.formattedAsMmolL)"
  325. )
  326. }
  327. Text(
  328. "This setting is limited to values between \(units == .mgdL ? "60" : 60.formattedAsMmolL) - \(units == .mgdL ? "120" : 120.formattedAsMmolL) \(units.rawValue)"
  329. )
  330. Text(
  331. "Note: Basal may be resumed if there is negative IOB and glucose is rising faster than the forecast."
  332. )
  333. }
  334. }
  335. }
  336. }
  337. }
  338. enum DiagnosticsSharingOption: String, Equatable, CaseIterable, Identifiable {
  339. case enabled
  340. case disabled
  341. var id: String { rawValue }
  342. var displayName: String {
  343. switch self {
  344. case .enabled:
  345. return String(localized: "Enable Sharing")
  346. case .disabled:
  347. return String(localized: "Disable Sharing")
  348. }
  349. }
  350. }
  351. enum PumpOptionForOnboardingUnits: String, Equatable, CaseIterable, Identifiable {
  352. case minimed
  353. case omnipodEros
  354. case omnipodDash
  355. case dana
  356. var id: String { rawValue }
  357. var displayName: String {
  358. switch self {
  359. case .minimed:
  360. return "Medtronic"
  361. case .omnipodEros:
  362. return "Omnipod Eros"
  363. case .omnipodDash:
  364. return "Omnipod Dash"
  365. case .dana:
  366. return "Dana (RS/-i)"
  367. }
  368. }
  369. }
  370. enum NightscoutSetupOption: String, Equatable, CaseIterable, Identifiable {
  371. case setupNightscout
  372. case skipNightscoutSetup
  373. case noSelection
  374. var id: String { rawValue }
  375. var displayName: String {
  376. switch self {
  377. case .setupNightscout:
  378. return String(localized: "Setup Nightscout for Trio")
  379. case .skipNightscoutSetup:
  380. return String(localized: "Skip Nightscout Setup")
  381. case .noSelection:
  382. return ""
  383. }
  384. }
  385. }
  386. enum NightscoutImportOption: String, Equatable, CaseIterable, Identifiable {
  387. case useImport
  388. case skipImport
  389. case noSelection
  390. var id: String { rawValue }
  391. var displayName: String {
  392. switch self {
  393. case .useImport:
  394. return String(localized: "Import Settings")
  395. case .skipImport:
  396. return String(localized: "Configure Yourself")
  397. case .noSelection:
  398. return ""
  399. }
  400. }
  401. }
  402. enum NightscoutSubstep: Int, CaseIterable, Identifiable {
  403. case setupSelection
  404. case connectToNightscout
  405. case importFromNightscout
  406. var id: Int { rawValue }
  407. }
  408. struct BulletPoint: View {
  409. let text: String
  410. init(_ text: String) {
  411. self.text = text
  412. }
  413. var body: some View {
  414. HStack(alignment: .top) {
  415. Text("•")
  416. Text(text)
  417. .fixedSize(horizontal: false, vertical: true)
  418. .multilineTextAlignment(.leading)
  419. }
  420. }
  421. }
  422. enum OnboardingInputSectionType: Equatable {
  423. case decimal
  424. case boolean
  425. static func == (lhs: OnboardingInputSectionType, rhs: OnboardingInputSectionType) -> Bool {
  426. switch (lhs, rhs) {
  427. case (.boolean, .boolean):
  428. return true
  429. case (.decimal, .decimal):
  430. return true
  431. default:
  432. return false
  433. }
  434. }
  435. }