NightscoutUploadView.swift 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. @Environment(AppState.self) var appState
  12. var body: some View {
  13. Form {
  14. SettingInputSection(
  15. decimalValue: $decimalPlaceholder,
  16. booleanValue: $state.isUploadEnabled,
  17. shouldDisplayHint: $shouldDisplayHint,
  18. selectedVerboseHint: Binding(
  19. get: { selectedVerboseHint },
  20. set: {
  21. selectedVerboseHint = $0
  22. hintLabel = "Allow Uploading to Nightscout"
  23. shouldDisplayHint = true
  24. }
  25. ),
  26. units: state.units,
  27. type: .boolean,
  28. label: "Allow Uploading to Nightscout",
  29. miniHint: "Enables upload of selected data sets to Nightscout. See hint for more details.",
  30. verboseHint: "The Upload Treatments toggle enables uploading of carbs, temp targets, device status, preferences and settings."
  31. )
  32. if state.changeUploadGlucose {
  33. SettingInputSection(
  34. decimalValue: $decimalPlaceholder,
  35. booleanValue: $state.uploadGlucose,
  36. shouldDisplayHint: $shouldDisplayHint,
  37. selectedVerboseHint: Binding(
  38. get: { selectedVerboseHint },
  39. set: {
  40. selectedVerboseHint = $0
  41. hintLabel = "Upload Glucose"
  42. shouldDisplayHint = true
  43. }
  44. ),
  45. units: state.units,
  46. type: .boolean,
  47. label: "Upload Glucose",
  48. miniHint: "Enables uploading of CGM readings to Nightscout.",
  49. verboseHint: "Write stuff here."
  50. )
  51. }
  52. }
  53. .sheet(isPresented: $shouldDisplayHint) {
  54. SettingInputHintView(
  55. hintDetent: $hintDetent,
  56. shouldDisplayHint: $shouldDisplayHint,
  57. hintLabel: hintLabel ?? "",
  58. hintText: selectedVerboseHint ?? "",
  59. sheetTitle: "Help"
  60. )
  61. }
  62. .navigationTitle("Upload")
  63. .navigationBarTitleDisplayMode(.automatic)
  64. .scrollContentBackground(.hidden)
  65. .background(appState.trioBackgroundColor(for: colorScheme))
  66. }
  67. }