PumpSettingsEditorRootView.swift 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. }
  40. // TODO: is max carbs now somewhere else?
  41. // HStack {
  42. // Text("Max Carbs")
  43. // TextFieldWithToolBar(text: $state.maxCarbs, placeholder: "g", numberFormatter: formatter)
  44. // }
  45. }
  46. Section(header: Text("Duration of Insulin Action")) {
  47. HStack {
  48. Text("DIA")
  49. TextFieldWithToolBar(text: $state.dia, placeholder: "hours", numberFormatter: formatter)
  50. }
  51. }
  52. Section {
  53. HStack {
  54. if state.syncInProgress {
  55. ProgressView().padding(.trailing, 10)
  56. }
  57. Button { state.save() }
  58. label: {
  59. Text(state.syncInProgress ? "Saving..." : "Save on Pump")
  60. }
  61. .disabled(state.syncInProgress)
  62. }
  63. }
  64. }
  65. .scrollContentBackground(.hidden).background(color)
  66. .onAppear(perform: configureView)
  67. .navigationTitle("Pump Settings")
  68. .navigationBarTitleDisplayMode(.automatic)
  69. }
  70. }
  71. }