ReviewInsulinActionView.swift 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. @Environment(AppState.self) var appState
  15. var body: some View {
  16. List {
  17. SettingInputSection(
  18. decimalValue: $state.importedInsulinActionCurve,
  19. booleanValue: $booleanPlaceholder,
  20. shouldDisplayHint: $shouldDisplayHint,
  21. selectedVerboseHint: Binding(
  22. get: { selectedVerboseHint },
  23. set: {
  24. selectedVerboseHint = $0.map { AnyView($0) }
  25. hintLabel = String(localized: "Duration of Insulin Action")
  26. }
  27. ),
  28. units: state.units,
  29. type: .decimal("dia"),
  30. label: String(localized: "Duration of Insulin Action"),
  31. miniHint: String(localized: "Number of hours insulin is active in your body."),
  32. verboseHint:
  33. VStack(alignment: .leading, spacing: 10) {
  34. Text("Default: 10 hours").bold()
  35. Text("Number of hours insulin will contribute to IOB after dosing.")
  36. Text(
  37. "Tip: It is better to use a Custom Peak Time than to adjust Duration of Insulin Action (DIA)."
  38. )
  39. },
  40. headerText: String(localized: "Review imported DIA")
  41. )
  42. }
  43. .sheet(isPresented: $shouldDisplayHint) {
  44. SettingInputHintView(
  45. hintDetent: $hintDetent,
  46. shouldDisplayHint: $shouldDisplayHint,
  47. hintLabel: hintLabel ?? "",
  48. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  49. sheetTitle: String(localized: "Help", comment: "Help sheet title")
  50. )
  51. }
  52. .scrollContentBackground(.hidden)
  53. .background(appState.trioBackgroundColor(for: colorScheme))
  54. .onAppear(perform: configureView)
  55. .navigationTitle("Duration of Insulin Action")
  56. .navigationBarTitleDisplayMode(.automatic)
  57. .onDisappear {
  58. state.saveReviewedInsulinAction()
  59. }
  60. }
  61. }