ReviewInsulinActionView.swift 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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",
  47. verboseHint:
  48. VStack(alignment: .leading, spacing: 10) {
  49. Text("Default: 6 hours").bold()
  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. },
  55. headerText: "Review imported DIA"
  56. )
  57. }
  58. .sheet(isPresented: $shouldDisplayHint) {
  59. SettingInputHintView(
  60. hintDetent: $hintDetent,
  61. shouldDisplayHint: $shouldDisplayHint,
  62. hintLabel: hintLabel ?? "",
  63. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  64. sheetTitle: "Help"
  65. )
  66. }
  67. .scrollContentBackground(.hidden).background(color)
  68. .onAppear(perform: configureView)
  69. .navigationTitle("Duration of Insulin Action")
  70. .navigationBarTitleDisplayMode(.automatic)
  71. .onDisappear {
  72. state.saveReviewedInsulinAction()
  73. }
  74. }
  75. }