PumpSettingsEditorRootView.swift 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. }
  24. Section(header: Text("Duration of Insulin Action")) {
  25. HStack {
  26. Text("DIA")
  27. DecimalTextField("hours", value: $state.dia, formatter: formatter)
  28. }
  29. }
  30. Section {
  31. HStack {
  32. if state.syncInProgress {
  33. ProgressView().padding(.trailing, 10)
  34. }
  35. Button { state.save() }
  36. label: {
  37. Text(state.syncInProgress ? "Saving..." : "Save on Pump")
  38. }
  39. .disabled(state.syncInProgress)
  40. }
  41. }
  42. }
  43. .onAppear(perform: configureView)
  44. .navigationTitle("Pump Settings")
  45. .navigationBarTitleDisplayMode(.automatic)
  46. }
  47. }
  48. }