HomeRootView+Header.swift 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import SwiftUI
  2. import UIKit
  3. // MARK: - Zone B: header (pump panel / glucose bobble / loop status)
  4. extension Home.RootView {
  5. var cgmSelectionButtons: some View {
  6. ForEach(cgmOptions, id: \.name) { option in
  7. if let cgm = state.listOfCGM.first(where: option.predicate) {
  8. Button(option.name) {
  9. state.addCGM(cgm: cgm)
  10. }
  11. }
  12. }
  13. }
  14. var glucoseView: some View {
  15. CurrentGlucoseView(
  16. timerDate: state.timerDate,
  17. units: state.units,
  18. alarm: state.alarm,
  19. lowGlucose: state.lowGlucose,
  20. highGlucose: state.highGlucose,
  21. cgmAvailable: state.cgmAvailable,
  22. currentGlucoseTarget: state.currentGlucoseTarget,
  23. glucoseColorScheme: state.glucoseColorScheme,
  24. glucose: state.latestTwoGlucoseValues,
  25. cgmProgress: state.cgmProgressHighlight,
  26. cgmStatus: state.cgmDisplayState,
  27. cgmSensorExpiresAt: state.cgmSensorExpiresAt,
  28. cgmWarmupEndsAt: state.cgmWarmupEndsAt
  29. )
  30. .onTapGesture {
  31. if !state.cgmAvailable {
  32. showCGMSelection.toggle()
  33. } else {
  34. state.shouldDisplayCGMSetupSheet.toggle()
  35. }
  36. }
  37. .onLongPressGesture {
  38. let impactHeavy = UIImpactFeedbackGenerator(style: .heavy)
  39. impactHeavy.impactOccurred()
  40. showSnoozeSheet = true
  41. }
  42. }
  43. var pumpView: some View {
  44. PumpView(
  45. reservoir: state.reservoir,
  46. name: state.pumpName,
  47. expiresAtDate: state.pumpExpiresAtDate,
  48. activatedAtDate: state.pumpActivatedAtDate,
  49. timerDate: state.timerDate,
  50. pumpStatusHighlightMessage: state.pumpStatusHighlightMessage,
  51. battery: state.batteryFromPersistence
  52. )
  53. .onTapGesture {
  54. if state.pumpDisplayState == nil {
  55. // shows user confirmation dialog with pump model choices, then proceeds to setup
  56. showPumpSelection.toggle()
  57. } else {
  58. // sends user to pump settings
  59. state.shouldDisplayPumpSetupSheet.toggle()
  60. }
  61. }
  62. }
  63. @ViewBuilder func rightHeaderPanel() -> some View {
  64. VStack(alignment: .leading, spacing: 20) {
  65. /// Loop view at bottomLeading
  66. LoopView(
  67. closedLoop: state.closedLoop,
  68. timerDate: state.timerDate,
  69. isLooping: state.isLooping,
  70. lastLoopDate: state.lastLoopDate,
  71. manualTempBasal: state.manualTempBasal,
  72. determination: state.determinationsFromPersistence
  73. )
  74. .onTapGesture {
  75. state.isLoopStatusPresented = true
  76. }
  77. /// eventualBG string at bottomTrailing
  78. if let eventualBG = state.enactedAndNonEnactedDeterminations.first?.eventualBG {
  79. let eventualGlucose = eventualBG as Decimal
  80. HStack {
  81. Image(systemName: "arrow.right.circle")
  82. .font(.callout)
  83. .fontWeight(.bold)
  84. Text(state.units == .mgdL ? eventualGlucose.description : eventualGlucose.formattedAsMmolL)
  85. .font(.callout)
  86. .fontWeight(.bold)
  87. .fontDesign(.rounded)
  88. }
  89. // aligns the evBG icon exactly with the first pixel of loop status icon
  90. .padding(.leading, 12)
  91. } else {
  92. HStack {
  93. Image(systemName: "arrow.right.circle")
  94. .font(.callout).fontWeight(.bold)
  95. Text("--")
  96. .font(.callout).fontWeight(.bold).fontDesign(.rounded)
  97. }
  98. }
  99. }
  100. }
  101. }