NightscoutUploadView.swift 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import SwiftUI
  2. struct NightscoutUploadView: View {
  3. @ObservedObject var state: NightscoutConfig.StateModel
  4. @State private var shouldDisplayHint: Bool = false
  5. @State var hintDetent = PresentationDetent.large
  6. @State var selectedVerboseHint: AnyView?
  7. @State var hintLabel: String?
  8. @State private var decimalPlaceholder: Decimal = 0.0
  9. @State private var booleanPlaceholder: Bool = false
  10. @Environment(\.colorScheme) var colorScheme
  11. @Environment(AppState.self) var appState
  12. var body: some View {
  13. List {
  14. SettingInputSection(
  15. decimalValue: $decimalPlaceholder,
  16. booleanValue: $state.isUploadEnabled,
  17. shouldDisplayHint: $shouldDisplayHint,
  18. selectedVerboseHint: Binding(
  19. get: { selectedVerboseHint },
  20. set: {
  21. selectedVerboseHint = $0.map { AnyView($0) }
  22. hintLabel = "Allow Uploading to Nightscout"
  23. shouldDisplayHint = true
  24. }
  25. ),
  26. units: state.units,
  27. type: .boolean,
  28. label: "Allow Uploading to Nightscout",
  29. miniHint: "Enable uploading of selected data sets to Nightscout.",
  30. verboseHint:
  31. VStack(alignment: .leading, spacing: 10) {
  32. Text("Default: OFF").bold()
  33. Text(
  34. "The Upload Treatments toggle enables uploading of the following data sets to your connected Nightscout URL:"
  35. )
  36. VStack(alignment: .leading, spacing: 5) {
  37. Text("• Carbs")
  38. Text("• Temp Targets")
  39. Text("• Device Status")
  40. Text("• Preferences")
  41. Text("• Settings")
  42. }
  43. }
  44. )
  45. if state.changeUploadGlucose {
  46. SettingInputSection(
  47. decimalValue: $decimalPlaceholder,
  48. booleanValue: $state.uploadGlucose,
  49. shouldDisplayHint: $shouldDisplayHint,
  50. selectedVerboseHint: Binding(
  51. get: { selectedVerboseHint },
  52. set: {
  53. selectedVerboseHint = $0.map { AnyView($0) }
  54. hintLabel = "Upload Glucose"
  55. shouldDisplayHint = true
  56. }
  57. ),
  58. units: state.units,
  59. type: .boolean,
  60. label: "Upload Glucose",
  61. miniHint: "Enable uploading of CGM readings to Nightscout.",
  62. verboseHint: VStack(alignment: .leading, spacing: 10) {
  63. Text("Default: OFF").bold()
  64. Text("Enabling this setting allows CGM readings from Trio to be used in Nightscout.")
  65. }
  66. )
  67. }
  68. }
  69. .listSectionSpacing(sectionSpacing)
  70. .sheet(isPresented: $shouldDisplayHint) {
  71. SettingInputHintView(
  72. hintDetent: $hintDetent,
  73. shouldDisplayHint: $shouldDisplayHint,
  74. hintLabel: hintLabel ?? "",
  75. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  76. sheetTitle: "Help"
  77. )
  78. }
  79. .navigationTitle("Upload")
  80. .navigationBarTitleDisplayMode(.automatic)
  81. .scrollContentBackground(.hidden)
  82. .background(appState.trioBackgroundColor(for: colorScheme))
  83. }
  84. }