ManualTempBasalRootView.swift 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import SwiftUI
  2. import Swinject
  3. extension ManualTempBasal {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @State var state = StateModel()
  7. @Environment(\.colorScheme) var colorScheme
  8. @Environment(AppState.self) var appState
  9. private var formatter: NumberFormatter {
  10. let formatter = NumberFormatter()
  11. formatter.numberStyle = .decimal
  12. formatter.maximumFractionDigits = 2
  13. return formatter
  14. }
  15. var body: some View {
  16. Form {
  17. Section {
  18. HStack {
  19. Text("Amount")
  20. Spacer()
  21. TextFieldWithToolBar(
  22. text: $state.rate,
  23. placeholder: "0",
  24. shouldBecomeFirstResponder: true,
  25. numberFormatter: formatter
  26. )
  27. Text("U/hr").foregroundColor(.secondary)
  28. }
  29. Picker(selection: $state.durationIndex, label: Text("Duration")) {
  30. ForEach(0 ..< state.durationValues.count) { index in
  31. Text(
  32. String(
  33. format: "%.0f h %02.0f min",
  34. state.durationValues[index] / 60 - 0.1,
  35. state.durationValues[index].truncatingRemainder(dividingBy: 60)
  36. )
  37. ).tag(index)
  38. }
  39. }
  40. }
  41. Section {
  42. Button { state.enact() }
  43. label: { Text("Enact") }
  44. Button { state.cancel() }
  45. label: { Text("Cancel Temp Basal") }
  46. }
  47. }
  48. .scrollContentBackground(.hidden).background(appState.trioBackgroundColor(for: colorScheme))
  49. .onAppear(perform: configureView)
  50. .navigationTitle("Manual Temp Basal")
  51. .navigationBarTitleDisplayMode(.automatic)
  52. .navigationBarItems(trailing: Button("Close", action: state.hideModal))
  53. }
  54. }
  55. }