ManualTempBasalRootView.swift 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. DecimalTextField("0", value: $state.rate, formatter: formatter, autofocus: true, cleanInput: true)
  20. Text("U/hr").foregroundColor(.secondary)
  21. }
  22. Picker(selection: $state.durationIndex, label: Text("Duration")) {
  23. ForEach(0 ..< state.durationValues.count) { index in
  24. Text(
  25. String(
  26. format: "%.0f h %02.0f min",
  27. state.durationValues[index] / 60 - 0.1,
  28. state.durationValues[index].truncatingRemainder(dividingBy: 60)
  29. )
  30. ).tag(index)
  31. }
  32. }
  33. }
  34. Section {
  35. Button { state.enact() }
  36. label: { Text("Enact") }
  37. Button { state.cancel() }
  38. label: { Text("Cancel Temp Basal") }
  39. }
  40. }
  41. .onAppear(perform: configureView)
  42. .navigationTitle("Manual Temp Basal")
  43. .navigationBarTitleDisplayMode(.automatic)
  44. .navigationBarItems(leading: Button("Close", action: state.hideModal))
  45. }
  46. }
  47. }