CGMRootView.swift 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import SwiftUI
  2. import Swinject
  3. extension CGM {
  4. struct RootView: BaseView {
  5. let resolver: Resolver
  6. @StateObject var state = StateModel()
  7. var body: some View {
  8. Form {
  9. Section {
  10. Picker("Type", selection: $state.cgm) {
  11. ForEach(CGMType.allCases) {
  12. Text($0.displayName).tag($0)
  13. }
  14. }
  15. }
  16. if [.dexcomG5, .dexcomG6].contains(state.cgm) {
  17. Section(header: Text("Transmitter ID")) {
  18. TextField("XXXXXX", text: $state.transmitterID, onCommit: {
  19. UIApplication.shared.endEditing()
  20. state.onChangeID()
  21. })
  22. .disableAutocorrection(true)
  23. .autocapitalization(.allCharacters)
  24. .keyboardType(.asciiCapable)
  25. }
  26. .onDisappear {
  27. state.onChangeID()
  28. }
  29. }
  30. if state.cgm == .libreTransmitter {
  31. Button("Configure Libre Transmitter") {
  32. state.showModal(for: .libreConfig)
  33. }
  34. Text("Calibrations").navigationLink(to: .calibrations, from: self)
  35. }
  36. Section(header: Text("Other")) {
  37. Toggle("Upload glucose to Nightscout", isOn: $state.uploadGlucose)
  38. }
  39. }
  40. .onAppear(perform: configureView)
  41. .navigationTitle("CGM")
  42. .navigationBarTitleDisplayMode(.automatic)
  43. }
  44. }
  45. }