NightscoutUploadView.swift 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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: "Enables upload of selected data sets to Nightscout",
  45. verboseHint: VStack(spacing: 10) {
  46. Text("Default: OFF").bold()
  47. VStack(alignment: .leading, spacing: 10) {
  48. Text(
  49. "The Upload Treatments toggle enables uploading of the following data sets to your connected Nightscout URL:"
  50. )
  51. VStack(alignment: .leading, spacing: 5) {
  52. Text("• Carbs")
  53. Text("• Temp Targets")
  54. Text("• Device Status")
  55. Text("• Preferences")
  56. Text("• Settings")
  57. }
  58. }
  59. }
  60. )
  61. if state.changeUploadGlucose {
  62. SettingInputSection(
  63. decimalValue: $decimalPlaceholder,
  64. booleanValue: $state.uploadGlucose,
  65. shouldDisplayHint: $shouldDisplayHint,
  66. selectedVerboseHint: Binding(
  67. get: { selectedVerboseHint },
  68. set: {
  69. selectedVerboseHint = $0.map { AnyView($0) }
  70. hintLabel = "Upload Glucose"
  71. shouldDisplayHint = true
  72. }
  73. ),
  74. units: state.units,
  75. type: .boolean,
  76. label: "Upload Glucose",
  77. miniHint: "Enables uploading of CGM readings to Nightscout",
  78. verboseHint: VStack(spacing: 10) {
  79. Text("Default: OFF").bold()
  80. Text("Enabling this setting allows CGM readings from Trio to be used in Nightscout.")
  81. }
  82. )
  83. }
  84. }
  85. .sheet(isPresented: $shouldDisplayHint) {
  86. SettingInputHintView(
  87. hintDetent: $hintDetent,
  88. shouldDisplayHint: $shouldDisplayHint,
  89. hintLabel: hintLabel ?? "",
  90. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  91. sheetTitle: "Help"
  92. )
  93. }
  94. .navigationTitle("Upload")
  95. .navigationBarTitleDisplayMode(.automatic)
  96. .scrollContentBackground(.hidden).background(color)
  97. }
  98. }