|
|
@@ -1,6 +1,7 @@
|
|
|
import SwiftUI
|
|
|
|
|
|
struct AddGlucoseAlertSheet: View {
|
|
|
+ @ObservedObject var store: GlucoseAlertsStore
|
|
|
let onPick: (GlucoseAlertType) -> Void
|
|
|
|
|
|
@Environment(\.dismiss) private var dismiss
|
|
|
@@ -12,7 +13,10 @@ struct AddGlucoseAlertSheet: View {
|
|
|
List {
|
|
|
Section {
|
|
|
ForEach(GlucoseAlertType.allCases) { type in
|
|
|
+ let available = store.availableActiveOptions(forNewAlarmOfType: type)
|
|
|
+ let isAvailable = !available.isEmpty
|
|
|
Button {
|
|
|
+ guard isAvailable else { return }
|
|
|
onPick(type)
|
|
|
dismiss()
|
|
|
} label: {
|
|
|
@@ -20,16 +24,20 @@ struct AddGlucoseAlertSheet: View {
|
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
|
Text(type.displayName)
|
|
|
.foregroundColor(.primary)
|
|
|
- Text(type.blurb)
|
|
|
+ Text(isAvailable ? type.blurb : unavailableHint(forType: type))
|
|
|
.font(.footnote)
|
|
|
.foregroundColor(.secondary)
|
|
|
}
|
|
|
Spacer()
|
|
|
- Image(systemName: "chevron.right")
|
|
|
- .font(.footnote)
|
|
|
- .foregroundColor(.secondary)
|
|
|
+ if isAvailable {
|
|
|
+ Image(systemName: "chevron.right")
|
|
|
+ .font(.footnote)
|
|
|
+ .foregroundColor(.secondary)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ .disabled(!isAvailable)
|
|
|
+ .opacity(isAvailable ? 1 : 0.5)
|
|
|
}
|
|
|
}.listRowBackground(Color.chart)
|
|
|
}
|
|
|
@@ -43,4 +51,8 @@ struct AddGlucoseAlertSheet: View {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ private func unavailableHint(forType type: GlucoseAlertType) -> String {
|
|
|
+ String(localized: "Already set for Day & Night. Delete one of these to add a new one.")
|
|
|
+ }
|
|
|
}
|