NightscoutUploadView.swift 3.1 KB

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