FastDropAlarmEditor.swift 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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: "This is how much the glucose must drop to be considered a fast drop.",
  17. title: "Falls by",
  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: "Number of Drops",
  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(alarm: $alarm, range: 0 ... 60, step: 5)
  47. }
  48. .navigationTitle(alarm.type.rawValue)
  49. }
  50. }