FastDropAlarmEditor.swift 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // LoopFollow
  2. // FastDropAlarmEditor.swift
  3. // Created by Jonas Björkert on 2025-05-11.
  4. import SwiftUI
  5. struct FastDropAlarmEditor: View {
  6. @Binding var alarm: Alarm
  7. @State private var useLimit: Bool = false
  8. var body: some View {
  9. Form {
  10. InfoBanner(
  11. text: "Alerts when glucose readings drop rapidly. For example, three straight readings each falling by at least the amount you set. Optionally limit alerts to only fire below a certain BG level."
  12. )
  13. AlarmGeneralSection(alarm: $alarm)
  14. AlarmBGSection(
  15. header: "Rate of Fall",
  16. footer: "How much the bg must fall to count as a “fast” drop.",
  17. title: "Drop per reading",
  18. range: 3 ... 20,
  19. value: Binding(
  20. get: { alarm.delta ?? 18 },
  21. set: { alarm.delta = $0 }
  22. )
  23. )
  24. // TODO: In the migration script, use 1 value less than stored since we are switching from readings to drops
  25. AlarmStepperSection(
  26. header: "Consecutive Drops",
  27. footer: "Number of drops—each meeting the rate above—required before an alert fires.",
  28. title: "Drops in a row",
  29. range: 1 ... 3,
  30. step: 1,
  31. value: Binding(
  32. get: { Double(alarm.monitoringWindow ?? 2) },
  33. set: { alarm.monitoringWindow = Int($0) }
  34. )
  35. )
  36. AlarmBGLimitSection(
  37. header: "BG Limit",
  38. footer: "When enabled, this alert only fires if the glucose is below the limit you set.",
  39. toggleText: "Use BG Limit",
  40. pickerTitle: "Dropping below",
  41. range: 40 ... 300,
  42. value: $alarm.belowBG
  43. )
  44. AlarmActiveSection(alarm: $alarm)
  45. AlarmAudioSection(alarm: $alarm)
  46. AlarmSnoozeSection(
  47. alarm: $alarm,
  48. range: 5 ... 60,
  49. step: 5
  50. )
  51. }
  52. .navigationTitle(alarm.type.rawValue)
  53. }
  54. }