NightscoutUploadView.swift 3.7 KB

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