ManualTempBasalRootView.swift 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import SwiftUI
  2. extension ManualTempBasal {
  3. struct RootView: BaseView {
  4. @EnvironmentObject var viewModel: ViewModel<Provider>
  5. private var formatter: NumberFormatter {
  6. let formatter = NumberFormatter()
  7. formatter.numberStyle = .decimal
  8. formatter.maximumFractionDigits = 0
  9. return formatter
  10. }
  11. var body: some View {
  12. Form {
  13. Section {
  14. HStack {
  15. Text("Amount")
  16. Spacer()
  17. DecimalTextField("0", value: $viewModel.rate, formatter: formatter, autofocus: true, cleanInput: true)
  18. Text("U/hour").foregroundColor(.secondary)
  19. }
  20. Picker(selection: $viewModel.durationIndex, label: Text("Duration")) {
  21. ForEach(0 ..< viewModel.durationValues.count) { index in
  22. Text(
  23. String(
  24. format: "%.0f h %02.0f min",
  25. viewModel.durationValues[index] / 60 - 0.1,
  26. viewModel.durationValues[index].truncatingRemainder(dividingBy: 60)
  27. )
  28. ).tag(index)
  29. }
  30. }
  31. }
  32. Section {
  33. Button { viewModel.enact() }
  34. label: { Text("Enact") }
  35. Button { viewModel.cancel() }
  36. label: { Text("Cancel Temp Basal") }
  37. }
  38. }
  39. .navigationTitle("Manual Temp Basal")
  40. .navigationBarTitleDisplayMode(.automatic)
  41. .navigationBarItems(leading: Button("Close", action: viewModel.hideModal))
  42. }
  43. }
  44. }