NightscoutUploadView.swift 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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: Text(
  46. "The Upload Treatments toggle enables uploading of carbs, temp targets, device status, preferences and settings."
  47. )
  48. )
  49. if state.changeUploadGlucose {
  50. SettingInputSection(
  51. decimalValue: $decimalPlaceholder,
  52. booleanValue: $state.uploadGlucose,
  53. shouldDisplayHint: $shouldDisplayHint,
  54. selectedVerboseHint: Binding(
  55. get: { selectedVerboseHint },
  56. set: {
  57. selectedVerboseHint = $0.map { AnyView($0) }
  58. hintLabel = "Upload Glucose"
  59. shouldDisplayHint = true
  60. }
  61. ),
  62. units: state.units,
  63. type: .boolean,
  64. label: "Upload Glucose",
  65. miniHint: "Enables uploading of CGM readings to Nightscout.",
  66. verboseHint: Text("Write stuff here.")
  67. )
  68. }
  69. }
  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).background(color)
  82. }
  83. }