ReviewInsulinActionView.swift 3.0 KB

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