CGMRootView.swift 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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) { type in
  12. VStack(alignment: .leading) {
  13. Text(type.displayName)
  14. Text(type.subtitle).font(.caption).foregroundColor(.secondary)
  15. }.tag(type)
  16. }
  17. }
  18. if let link = state.cgm.externalLink {
  19. Button("About this source") {
  20. UIApplication.shared.open(link, options: [:], completionHandler: nil)
  21. }
  22. }
  23. }
  24. if [.dexcomG5, .dexcomG6].contains(state.cgm) {
  25. Section(header: Text("Transmitter ID")) {
  26. TextField("XXXXXX", text: $state.transmitterID, onCommit: {
  27. UIApplication.shared.endEditing()
  28. state.onChangeID()
  29. })
  30. .disableAutocorrection(true)
  31. .autocapitalization(.allCharacters)
  32. .keyboardType(.asciiCapable)
  33. }
  34. .onDisappear {
  35. state.onChangeID()
  36. }
  37. }
  38. if state.cgm == .libreTransmitter {
  39. Button("Configure Libre Transmitter") {
  40. state.showModal(for: .libreConfig)
  41. }
  42. Text("Calibrations").navigationLink(to: .calibrations, from: self)
  43. }
  44. Section(header: Text("Calendar")) {
  45. Toggle("Create events in calendar", isOn: $state.createCalendarEvents)
  46. if state.calendarIDs.isNotEmpty {
  47. Picker("Calendar", selection: $state.currentCalendarID) {
  48. ForEach(state.calendarIDs, id: \.self) {
  49. Text($0).tag($0)
  50. }
  51. }
  52. }
  53. }
  54. Section(header: Text("Other")) {
  55. Toggle("Upload glucose to Nightscout", isOn: $state.uploadGlucose)
  56. }
  57. }
  58. .onAppear(perform: configureView)
  59. .navigationTitle("CGM")
  60. .navigationBarTitleDisplayMode(.automatic)
  61. }
  62. }
  63. }