CGMRootView.swift 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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("Calendar")) {
  37. Toggle("Create events in calendar", isOn: $state.createCalendarEvents)
  38. if state.calendarIDs.isNotEmpty {
  39. Picker("Calendar", selection: $state.currentCalendarID) {
  40. ForEach(state.calendarIDs, id: \.self) {
  41. Text($0).tag($0)
  42. }
  43. }
  44. }
  45. }
  46. Section(header: Text("Other")) {
  47. Toggle("Upload glucose to Nightscout", isOn: $state.uploadGlucose)
  48. }
  49. }
  50. .onAppear(perform: configureView)
  51. .navigationTitle("CGM")
  52. .navigationBarTitleDisplayMode(.automatic)
  53. }
  54. }
  55. }