PumpSettingsEditorRootView.swift 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import SwiftUI
  2. import Swinject
  3. extension PumpSettingsEditor {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @StateObject var state = StateModel()
  7. private var formatter: NumberFormatter {
  8. let formatter = NumberFormatter()
  9. formatter.numberStyle = .decimal
  10. return formatter
  11. }
  12. var body: some View {
  13. Form {
  14. Section(header: Text("Delivery limits")) {
  15. HStack {
  16. Text("Max Basal")
  17. DecimalTextField("U/hr", value: $state.maxBasal, formatter: formatter)
  18. }
  19. HStack {
  20. Text("Max Bolus")
  21. DecimalTextField("U", value: $state.maxBolus, formatter: formatter)
  22. }
  23. HStack {
  24. Text("Max Carbs")
  25. DecimalTextField("g", value: $state.maxCarbs, formatter: formatter)
  26. }
  27. }
  28. Section(header: Text("Duration of Insulin Action")) {
  29. HStack {
  30. Text("DIA")
  31. DecimalTextField("hours", value: $state.dia, formatter: formatter)
  32. }
  33. }
  34. Section {
  35. HStack {
  36. if state.syncInProgress {
  37. ProgressView().padding(.trailing, 10)
  38. }
  39. Button { state.save() }
  40. label: {
  41. Text(state.syncInProgress ? "Saving..." : "Save on Pump")
  42. }
  43. .disabled(state.syncInProgress)
  44. }
  45. }
  46. }
  47. .onAppear(perform: configureView)
  48. .navigationTitle("Pump Settings")
  49. .navigationBarTitleDisplayMode(.automatic)
  50. }
  51. }
  52. }