NightscoutFetchView.swift 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import SwiftUI
  2. struct NightscoutFetchView: 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.isDownloadEnabled,
  17. shouldDisplayHint: $shouldDisplayHint,
  18. selectedVerboseHint: Binding(
  19. get: { selectedVerboseHint },
  20. set: {
  21. selectedVerboseHint = $0
  22. hintLabel = "Allow Fetching from Nightscout"
  23. }
  24. ),
  25. units: state.units,
  26. type: .boolean,
  27. label: "Allow Fetching from Nightscout",
  28. miniHint: "Enable fetching of selected data sets from Nightscout. See hint for more details.",
  29. verboseHint: "The Fetch Treatments toggle enables fetching of carbs and temp targets entered in Careportal or by another uploading device than Trio from Nightscout.",
  30. headerText: "Remote & Fetch Capabilities"
  31. )
  32. if state.isDownloadEnabled {
  33. SettingInputSection(
  34. decimalValue: $decimalPlaceholder,
  35. booleanValue: $state.allowAnnouncements,
  36. shouldDisplayHint: $shouldDisplayHint,
  37. selectedVerboseHint: Binding(
  38. get: { selectedVerboseHint },
  39. set: {
  40. selectedVerboseHint = $0
  41. hintLabel = "Allow Remote Control of Trio"
  42. }
  43. ),
  44. units: state.units,
  45. type: .boolean,
  46. label: "Allow Remote Control of Trio",
  47. miniHint: "Enables selected remote control capabilities via Nightscout. See hint for more details.",
  48. verboseHint: "When enabled you allow these remote functions through announcements from Nightscout: \n • Suspend/Resume Pump \n • Opening/Closing Loop \n • Set Temp Basal \n • Enact Bolus"
  49. )
  50. } else {
  51. Section {
  52. Text("'Allow Fetching from Nightscout' must be enabled to allow for Trio Remote Control.")
  53. }.listRowBackground(Color.tabBar)
  54. }
  55. }
  56. .sheet(isPresented: $shouldDisplayHint) {
  57. SettingInputHintView(
  58. hintDetent: $hintDetent,
  59. shouldDisplayHint: $shouldDisplayHint,
  60. hintLabel: hintLabel ?? "",
  61. hintText: selectedVerboseHint ?? "",
  62. sheetTitle: "Help"
  63. )
  64. }
  65. .navigationTitle("Fetch & Remote")
  66. .navigationBarTitleDisplayMode(.automatic)
  67. .scrollContentBackground(.hidden)
  68. .background(appState.trioBackgroundColor(for: colorScheme))
  69. }
  70. }