NightscoutFetchView.swift 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 = String(localized: "Allow Fetching from Nightscout")
  23. }
  24. ),
  25. units: state.units,
  26. type: .boolean,
  27. label: String(localized: "Allow Fetching from Nightscout"),
  28. miniHint: String(localized: "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: String(localized: "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: String(localized: "Help", comment: "Help sheet title")
  46. )
  47. }
  48. .navigationTitle("Fetch")
  49. .navigationBarTitleDisplayMode(.automatic)
  50. .settingsHighlightScroll()
  51. .scrollContentBackground(.hidden)
  52. .background(appState.trioBackgroundColor(for: colorScheme))
  53. }
  54. }