|
|
@@ -87,11 +87,13 @@ extension TargetsEditor {
|
|
|
.navigationTitle("Target Glucose")
|
|
|
.navigationBarTitleDisplayMode(.automatic)
|
|
|
.toolbar(content: {
|
|
|
- ToolbarItem(placement: .topBarTrailing) {
|
|
|
- EditButton()
|
|
|
+ if state.items.isNotEmpty {
|
|
|
+ ToolbarItem(placement: .topBarTrailing) {
|
|
|
+ EditButton()
|
|
|
+ }
|
|
|
}
|
|
|
ToolbarItem(placement: .topBarTrailing) {
|
|
|
- addButton
|
|
|
+ Button(action: { state.add() }) { Image(systemName: "plus") }.disabled(!state.canAdd)
|
|
|
}
|
|
|
})
|
|
|
.environment(\.editMode, $editMode)
|
|
|
@@ -102,6 +104,16 @@ extension TargetsEditor {
|
|
|
|
|
|
private func pickers(for index: Int) -> some View {
|
|
|
Form {
|
|
|
+ if !state.canAdd {
|
|
|
+ Section {
|
|
|
+ VStack(alignment: .leading) {
|
|
|
+ Text(
|
|
|
+ "Target Glucose covered for 24 hours. You cannot add more rates. Please remove or adjust existing rates to make space."
|
|
|
+ ).bold()
|
|
|
+ }
|
|
|
+ }.listRowBackground(Color.tabBar)
|
|
|
+ }
|
|
|
+
|
|
|
Section {
|
|
|
Picker(
|
|
|
selection: $state.items[index].lowIndex,
|
|
|
@@ -206,23 +218,6 @@ extension TargetsEditor {
|
|
|
}.chartYScale(domain: (state.units == .mgdL ? 72 : 4.0) ... (state.units == .mgdL ? 180 : 10))
|
|
|
}
|
|
|
|
|
|
- private var addButton: some View {
|
|
|
- guard state.canAdd else {
|
|
|
- return AnyView(EmptyView())
|
|
|
- }
|
|
|
-
|
|
|
- switch editMode {
|
|
|
- case .inactive:
|
|
|
- return AnyView(Button(action: onAdd) { Image(systemName: "plus") })
|
|
|
- default:
|
|
|
- return AnyView(EmptyView())
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- func onAdd() {
|
|
|
- state.add()
|
|
|
- }
|
|
|
-
|
|
|
private func onDelete(offsets: IndexSet) {
|
|
|
state.items.remove(atOffsets: offsets)
|
|
|
state.validate()
|