ManualTempBasalRootView.swift 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import SwiftUI
  2. import Swinject
  3. extension ManualTempBasal {
  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. formatter.maximumFractionDigits = 2
  11. return formatter
  12. }
  13. var body: some View {
  14. Form {
  15. Section {
  16. HStack {
  17. Text("Amount")
  18. Spacer()
  19. TextFieldWithToolBar(
  20. text: $state.rate,
  21. placeholder: "0",
  22. shouldBecomeFirstResponder: true,
  23. numberFormatter: formatter
  24. )
  25. Text("U/hr").foregroundColor(.secondary)
  26. }
  27. Picker(selection: $state.durationIndex, label: Text("Duration")) {
  28. ForEach(0 ..< state.durationValues.count) { index in
  29. Text(
  30. String(
  31. format: "%.0f h %02.0f min",
  32. state.durationValues[index] / 60 - 0.1,
  33. state.durationValues[index].truncatingRemainder(dividingBy: 60)
  34. )
  35. ).tag(index)
  36. }
  37. }
  38. }
  39. Section {
  40. Button { state.enact() }
  41. label: { Text("Enact") }
  42. Button { state.cancel() }
  43. label: { Text("Cancel Temp Basal") }
  44. }
  45. }
  46. .onAppear(perform: configureView)
  47. .navigationTitle("Manual Temp Basal")
  48. .navigationBarTitleDisplayMode(.automatic)
  49. .navigationBarItems(leading: Button("Close", action: state.hideModal))
  50. }
  51. }
  52. }