NightscoutFetchView.swift 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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: 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.isDownloadEnabled,
  17. shouldDisplayHint: $shouldDisplayHint,
  18. selectedVerboseHint: Binding(
  19. get: { selectedVerboseHint },
  20. set: {
  21. selectedVerboseHint = $0.map { AnyView($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.",
  29. verboseHint: VStack(alignment: .leading, spacing: 10) {
  30. Text("Default: OFF").bold()
  31. Text(
  32. "The Fetch Treatments toggle enables fetching of carbs and temp targets entered in Careportal or by another uploading device than Trio from Nightscout."
  33. )
  34. },
  35. headerText: "Fetch NS Care Portal Data"
  36. )
  37. }
  38. .listSectionSpacing(sectionSpacing)
  39. .sheet(isPresented: $shouldDisplayHint) {
  40. SettingInputHintView(
  41. hintDetent: $hintDetent,
  42. shouldDisplayHint: $shouldDisplayHint,
  43. hintLabel: hintLabel ?? "",
  44. hintText: selectedVerboseHint ?? AnyView(EmptyView()),
  45. sheetTitle: "Help"
  46. )
  47. }
  48. .navigationTitle("Fetch")
  49. .navigationBarTitleDisplayMode(.automatic)
  50. .scrollContentBackground(.hidden)
  51. .background(appState.trioBackgroundColor(for: colorScheme))
  52. }
  53. }