NightscoutUploadView.swift 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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: String?
  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
  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: "The Upload Treatments toggle enables uploading of carbs, temp targets, device status, preferences and settings."
  46. )
  47. if state.changeUploadGlucose {
  48. SettingInputSection(
  49. decimalValue: $decimalPlaceholder,
  50. booleanValue: $state.uploadGlucose,
  51. shouldDisplayHint: $shouldDisplayHint,
  52. selectedVerboseHint: Binding(
  53. get: { selectedVerboseHint },
  54. set: {
  55. selectedVerboseHint = $0
  56. hintLabel = "Upload Glucose"
  57. shouldDisplayHint = true
  58. }
  59. ),
  60. units: state.units,
  61. type: .boolean,
  62. label: "Upload Glucose",
  63. miniHint: "Enables uploading of CGM readings to Nightscout.",
  64. verboseHint: "Write stuff here."
  65. )
  66. }
  67. }
  68. .sheet(isPresented: $shouldDisplayHint) {
  69. SettingInputHintView(
  70. hintDetent: $hintDetent,
  71. shouldDisplayHint: $shouldDisplayHint,
  72. hintLabel: hintLabel ?? "",
  73. hintText: selectedVerboseHint ?? "",
  74. sheetTitle: "Help"
  75. )
  76. }
  77. .navigationTitle("Upload")
  78. .navigationBarTitleDisplayMode(.automatic)
  79. .scrollContentBackground(.hidden).background(color)
  80. }
  81. }