NightscoutUploadView.swift 3.7 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. @Environment(AppState.self) var appState
  12. var body: some View {
  13. List {
  14. SettingInputSection(
  15. decimalValue: $decimalPlaceholder,
  16. booleanValue: $state.isUploadEnabled,
  17. shouldDisplayHint: $shouldDisplayHint,
  18. selectedVerboseHint: Binding(
  19. get: { selectedVerboseHint },
  20. set: {
  21. selectedVerboseHint = $0.map { AnyView($0) }
  22. hintLabel = String(localized: "Allow Uploading to Nightscout")
  23. shouldDisplayHint = true
  24. }
  25. ),
  26. units: state.units,
  27. type: .boolean,
  28. label: String(localized: "Allow Uploading to Nightscout"),
  29. miniHint: String(localized: "Enable uploading of selected data sets to Nightscout."),
  30. verboseHint:
  31. VStack(alignment: .leading, spacing: 10) {
  32. Text("Default: OFF").bold()
  33. Text(
  34. "The Upload Treatments toggle enables uploading of the following data sets to your connected Nightscout URL:"
  35. )
  36. VStack(alignment: .leading, spacing: 5) {
  37. Text("• Carbs")
  38. Text("• Temp Targets")
  39. Text("• Device Status")
  40. Text("• Preferences")
  41. Text("• Settings")
  42. }
  43. }
  44. )
  45. SettingInputSection(
  46. decimalValue: $decimalPlaceholder,
  47. booleanValue: $state.uploadGlucose,
  48. shouldDisplayHint: $shouldDisplayHint,
  49. selectedVerboseHint: Binding(
  50. get: { selectedVerboseHint },
  51. set: {
  52. selectedVerboseHint = $0.map { AnyView($0) }
  53. hintLabel = String(localized: "Upload Glucose")
  54. shouldDisplayHint = true
  55. }
  56. ),
  57. units: state.units,
  58. type: .boolean,
  59. label: String(localized: "Upload Glucose"),
  60. miniHint: String(localized: "Enable uploading of CGM readings to Nightscout."),
  61. verboseHint: VStack(alignment: .leading, spacing: 10) {
  62. Text("Default: OFF").bold()
  63. Text("Enabling this setting allows CGM readings from Trio to be used in Nightscout.")
  64. }
  65. )
  66. }
  67. .listSectionSpacing(sectionSpacing)
  68. .sheet(isPresented: $shouldDisplayHint) {
  69. SettingInputHintView(
  70. hintDetent: $hintDetent,
  71. shouldDisplayHint: $shouldDisplayHint,
  72. hintLabel: hintLabel ?? "",
  73. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  74. sheetTitle: String(localized: "Help", comment: "Help sheet title")
  75. )
  76. }
  77. .navigationTitle("Upload")
  78. .navigationBarTitleDisplayMode(.automatic)
  79. .settingsHighlightScroll()
  80. .scrollContentBackground(.hidden)
  81. .background(appState.trioBackgroundColor(for: colorScheme))
  82. }
  83. }