ReviewInsulinActionView.swift 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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: "Number of hours insulin is active in your body \nDefault: 6 hours",
  47. verboseHint: VStack(spacing: 10) {
  48. Text("Default: 6 hours").bold()
  49. VStack(alignment: .leading, spacing: 10) {
  50. Text("Number of hours insulin will contribute to IOB after dosing.")
  51. Text(
  52. "Tip: It is better to use Custom Peak Timing rather than use a Duration of Insulin Action (DIA) other than the default of 6 hours."
  53. )
  54. .italic()
  55. }
  56. },
  57. headerText: "Review imported DIA"
  58. )
  59. }
  60. .sheet(isPresented: $shouldDisplayHint) {
  61. SettingInputHintView(
  62. hintDetent: $hintDetent,
  63. shouldDisplayHint: $shouldDisplayHint,
  64. hintLabel: hintLabel ?? "",
  65. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  66. sheetTitle: "Help"
  67. )
  68. }
  69. .scrollContentBackground(.hidden).background(color)
  70. .onAppear(perform: configureView)
  71. .navigationTitle("Duration of Insulin Action")
  72. .navigationBarTitleDisplayMode(.automatic)
  73. .onDisappear {
  74. state.saveReviewedInsulinAction()
  75. }
  76. }
  77. }