NightscoutUploadView.swift 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. var color: LinearGradient {
  12. colorScheme == .dark ? LinearGradient(
  13. gradient: Gradient(colors: [
  14. Color.bgDarkBlue,
  15. Color.bgDarkerDarkBlue
  16. ]),
  17. startPoint: .top,
  18. endPoint: .bottom
  19. )
  20. :
  21. LinearGradient(
  22. gradient: Gradient(colors: [Color.gray.opacity(0.1)]),
  23. startPoint: .top,
  24. endPoint: .bottom
  25. )
  26. }
  27. var body: some View {
  28. Form {
  29. SettingInputSection(
  30. decimalValue: $decimalPlaceholder,
  31. booleanValue: $state.isUploadEnabled,
  32. shouldDisplayHint: $shouldDisplayHint,
  33. selectedVerboseHint: Binding(
  34. get: { selectedVerboseHint },
  35. set: {
  36. selectedVerboseHint = $0.map { AnyView($0) }
  37. hintLabel = "Allow Uploading to Nightscout"
  38. shouldDisplayHint = true
  39. }
  40. ),
  41. units: state.units,
  42. type: .boolean,
  43. label: "Allow Uploading to Nightscout",
  44. miniHint: """
  45. Enables upload of selected data sets to Nightscout
  46. See hint for more details
  47. """,
  48. verboseHint: VStack(spacing: 5) {
  49. Text("The Upload Treatments toggle enables uploading of:")
  50. VStack(alignment: .leading) {
  51. Text("• Carbs")
  52. Text("• Temp Targets")
  53. Text("• Device Status")
  54. Text("• Preferences")
  55. Text("• Settings")
  56. }
  57. }
  58. )
  59. if state.changeUploadGlucose {
  60. SettingInputSection(
  61. decimalValue: $decimalPlaceholder,
  62. booleanValue: $state.uploadGlucose,
  63. shouldDisplayHint: $shouldDisplayHint,
  64. selectedVerboseHint: Binding(
  65. get: { selectedVerboseHint },
  66. set: {
  67. selectedVerboseHint = $0.map { AnyView($0) }
  68. hintLabel = "Upload Glucose"
  69. shouldDisplayHint = true
  70. }
  71. ),
  72. units: state.units,
  73. type: .boolean,
  74. label: "Upload Glucose",
  75. miniHint: "Enables uploading of CGM readings to Nightscout",
  76. verboseHint: Text(
  77. "Enabling this setting allows CGM readings from Trio to be used in Nightscout."
  78. )
  79. )
  80. }
  81. }
  82. .sheet(isPresented: $shouldDisplayHint) {
  83. SettingInputHintView(
  84. hintDetent: $hintDetent,
  85. shouldDisplayHint: $shouldDisplayHint,
  86. hintLabel: hintLabel ?? "",
  87. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  88. sheetTitle: "Help"
  89. )
  90. }
  91. .navigationTitle("Upload")
  92. .navigationBarTitleDisplayMode(.automatic)
  93. .scrollContentBackground(.hidden).background(color)
  94. }
  95. }