ReviewInsulinActionView.swift 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import Foundation
  2. import SwiftUI
  3. import Swinject
  4. struct ReviewInsulinActionView: BaseView {
  5. var resolver: any Swinject.Resolver
  6. @ObservedObject var state: NightscoutConfig.StateModel
  7. @State private var shouldDisplayHint: Bool = false
  8. @State private var hintDetent = PresentationDetent.large
  9. @State private var selectedVerboseHint: AnyView?
  10. @State private 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. var body: some View {
  31. List {
  32. SettingInputSection(
  33. decimalValue: $state.importedInsulinActionCurve,
  34. booleanValue: $booleanPlaceholder,
  35. shouldDisplayHint: $shouldDisplayHint,
  36. selectedVerboseHint: Binding(
  37. get: { selectedVerboseHint },
  38. set: {
  39. selectedVerboseHint = $0.map { AnyView($0) }
  40. hintLabel = "Duration of Insulin Action"
  41. }
  42. ),
  43. units: state.units,
  44. type: .decimal("dia"),
  45. label: "Duration of Insulin Action",
  46. miniHint: """
  47. Number of hours insulin is active in your body
  48. Default: 6 hours
  49. """,
  50. verboseHint: VStack {
  51. Text("Default: 6 hours").bold()
  52. Text("""
  53. Number of hours insulin will contribute to IOB after dosing.
  54. """)
  55. Text("It is better to use Custom Peak Timing rather than adjust your Duration of Insulin Action (DIA)")
  56. .italic()
  57. },
  58. headerText: "Review imported DIA"
  59. )
  60. }
  61. .sheet(isPresented: $shouldDisplayHint) {
  62. SettingInputHintView(
  63. hintDetent: $hintDetent,
  64. shouldDisplayHint: $shouldDisplayHint,
  65. hintLabel: hintLabel ?? "",
  66. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  67. sheetTitle: "Help"
  68. )
  69. }
  70. .scrollContentBackground(.hidden).background(color)
  71. .onAppear(perform: configureView)
  72. .navigationTitle("Duration of Insulin Action")
  73. .navigationBarTitleDisplayMode(.automatic)
  74. .onDisappear {
  75. state.saveReviewedInsulinAction()
  76. }
  77. }
  78. }