PumpSettingsEditorRootView.swift 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import SwiftUI
  2. import Swinject
  3. extension PumpSettingsEditor {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @StateObject var state = StateModel()
  7. @Environment(\.colorScheme) var colorScheme
  8. var color: LinearGradient {
  9. colorScheme == .dark ? LinearGradient(
  10. gradient: Gradient(colors: [
  11. Color.bgDarkBlue,
  12. Color.bgDarkerDarkBlue
  13. ]),
  14. startPoint: .top,
  15. endPoint: .bottom
  16. )
  17. :
  18. LinearGradient(
  19. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  20. startPoint: .top,
  21. endPoint: .bottom
  22. )
  23. }
  24. private var formatter: NumberFormatter {
  25. let formatter = NumberFormatter()
  26. formatter.numberStyle = .decimal
  27. return formatter
  28. }
  29. var body: some View {
  30. Form {
  31. Section(header: Text("Delivery limits")) {
  32. HStack {
  33. Text("Max Basal")
  34. DecimalTextField("U/hr", value: $state.maxBasal, formatter: formatter)
  35. }
  36. HStack {
  37. Text("Max Bolus")
  38. DecimalTextField("U", value: $state.maxBolus, formatter: formatter)
  39. }
  40. HStack {
  41. Text("Max Carbs")
  42. DecimalTextField("g", value: $state.maxCarbs, formatter: formatter)
  43. }
  44. }
  45. Section(header: Text("Duration of Insulin Action")) {
  46. HStack {
  47. Text("DIA")
  48. DecimalTextField("hours", value: $state.dia, formatter: formatter)
  49. }
  50. }
  51. Section {
  52. HStack {
  53. if state.syncInProgress {
  54. ProgressView().padding(.trailing, 10)
  55. }
  56. Button { state.save() }
  57. label: {
  58. Text(state.syncInProgress ? "Saving..." : "Save on Pump")
  59. }
  60. .disabled(state.syncInProgress)
  61. }
  62. }
  63. }
  64. .scrollContentBackground(.hidden).background(color)
  65. .onAppear(perform: configureView)
  66. .navigationTitle("Pump Settings")
  67. .navigationBarTitleDisplayMode(.automatic)
  68. }
  69. }
  70. }