PumpSettingsEditorRootView.swift 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. TextFieldWithToolBar(text: $state.maxBasal, placeholder: "U/hr", numberFormatter: formatter)
  35. }
  36. HStack {
  37. Text("Max Bolus")
  38. TextFieldWithToolBar(text: $state.maxBolus, placeholder: "U", numberFormatter: formatter)
  39. <<<<<<< HEAD
  40. }
  41. HStack {
  42. Text("Max Carbs")
  43. TextFieldWithToolBar(text: $state.maxCarbs, placeholder: "g", numberFormatter: formatter)
  44. =======
  45. >>>>>>> 9672da256c317a314acc76d6e4f6e82cc174d133
  46. }
  47. }
  48. Section(header: Text("Duration of Insulin Action")) {
  49. HStack {
  50. Text("DIA")
  51. TextFieldWithToolBar(text: $state.dia, placeholder: "hours", numberFormatter: formatter)
  52. }
  53. }
  54. Section {
  55. HStack {
  56. if state.syncInProgress {
  57. ProgressView().padding(.trailing, 10)
  58. }
  59. Button { state.save() }
  60. label: {
  61. Text(state.syncInProgress ? "Saving..." : "Save on Pump")
  62. }
  63. .disabled(state.syncInProgress)
  64. }
  65. }
  66. }
  67. .scrollContentBackground(.hidden).background(color)
  68. .onAppear(perform: configureView)
  69. .navigationTitle("Pump Settings")
  70. .navigationBarTitleDisplayMode(.automatic)
  71. }
  72. }
  73. }