فهرست منبع

A hack to make it appear as not saved until you enact or tap "Save"

Jon Mårtensson 2 سال پیش
والد
کامیت
8a1fae698a

+ 1 - 1
FreeAPS/Sources/Modules/AddCarbs/View/AddCarbsRootView.swift

@@ -119,7 +119,7 @@ extension AddCarbs {
 
                 Section {
                     Button { state.add() }
-                    label: { Text(state.carbs > 0 ? "Save and continue" : "Save") }
+                    label: { Text(state.carbs > 0 ? "Continue" : "Save") }
                         .disabled(state.carbs <= 0 && state.fat <= 0 && state.protein <= 0)
                         .frame(maxWidth: .infinity, alignment: .center)
                 } footer: { Text(state.waitersNotepad().description) }

+ 14 - 10
FreeAPS/Sources/Modules/Bolus/BolusStateModel.swift

@@ -219,21 +219,25 @@ extension Bolus {
         }
 
         func backToCarbsView(complexEntry: Bool, _ id: String) {
-            if complexEntry {
-                DispatchQueue.safeMainSync {
-                    nsManager.deleteCarbs(
-                        at: id, isFPU: nil, fpuID: nil, syncID: id
-                    )
-                    nsManager.deleteCarbs(
-                        at: id + ".fpu", isFPU: nil, fpuID: nil, syncID: id
-                    )
-                }
+            delete(deleteTwice: complexEntry, id: id)
+            showModal(for: .addCarbs(editMode: complexEntry))
+        }
+
+        func delete(deleteTwice: Bool, id: String) {
+            if deleteTwice {
+                // DispatchQueue.safeMainSync {
+                nsManager.deleteCarbs(
+                    at: id, isFPU: nil, fpuID: nil, syncID: id
+                )
+                nsManager.deleteCarbs(
+                    at: id + ".fpu", isFPU: nil, fpuID: nil, syncID: id
+                )
+                // }
             } else {
                 nsManager.deleteCarbs(
                     at: id, isFPU: nil, fpuID: nil, syncID: id
                 )
             }
-            showModal(for: .addCarbs(editMode: complexEntry))
         }
     }
 }

+ 22 - 6
FreeAPS/Sources/Modules/Bolus/View/AlternativeBolusCalcRootView.swift

@@ -11,6 +11,7 @@ extension Bolus {
         @StateObject var state: StateModel
         @State private var showInfo = false
         @State private var exceededMaxBolus = false
+        @State private var keepForNextWiew: Bool = false
 
         private enum Config {
             static let dividerHeight: CGFloat = 2
@@ -106,9 +107,10 @@ extension Bolus {
                 Section {
                     Button {
                         let id_ = meal.first?.id ?? ""
+                        keepForNextWiew = true
                         state.backToCarbsView(complexEntry: fetch, id_)
                     }
-                    label: { Text(fetch ? "Delete and Go Back" : "Add Meal") }.frame(maxWidth: .infinity, alignment: .center)
+                    label: { Text(fetch ? "Edit Meal" : "Add Meal") }.frame(maxWidth: .infinity, alignment: .center)
                 }
 
                 Section {
@@ -182,10 +184,16 @@ extension Bolus {
 
                 Section {
                     if state.amount == 0, waitForSuggestion {
-                        Button { state.showModal(for: nil) }
+                        Button {
+                            keepForNextWiew = true
+                            state.showModal(for: nil)
+                        }
                         label: { Text("Continue without bolus") }.frame(maxWidth: .infinity, alignment: .center)
                     } else {
-                        Button { state.add() }
+                        Button {
+                            keepForNextWiew = true
+                            state.add()
+                        }
                         label: { Text(exceededMaxBolus ? "Max Bolus exceeded!" : "Enact bolus") }
                             .frame(maxWidth: .infinity, alignment: .center)
                             .foregroundColor(exceededMaxBolus ? .loopRed : .accentColor)
@@ -198,8 +206,10 @@ extension Bolus {
             .blur(radius: showInfo ? 3 : 0)
             .navigationTitle("Enact Bolus")
             .navigationBarTitleDisplayMode(.inline)
-            .navigationBarItems(leading: Button("Close", action: state.hideModal))
-
+            .navigationBarItems(
+                leading: Button { state.hideModal() }
+                label: { Text("Close") }
+            )
             .onAppear {
                 configureView {
                     state.waitForSuggestionInitial = waitForSuggestion
@@ -207,7 +217,13 @@ extension Bolus {
                     state.insulinCalculated = state.calculateInsulin()
                 }
             }
-
+            .onDisappear {
+                if fetch, hasFatOrProtein, !keepForNextWiew {
+                    state.delete(deleteTwice: true, id: meal.first?.id ?? "")
+                } else if fetch, !keepForNextWiew {
+                    state.delete(deleteTwice: false, id: meal.first?.id ?? "")
+                }
+            }
             .popup(isPresented: showInfo) {
                 bolusInfoAlternativeCalculator
             }