Просмотр исходного кода

Small fixes for new bolus calc (#290)

* update enact bolus button description when amount exceeds maxBolus and fix insulin unit description

* reimplement continue without bolus button, delete unnecessary code in BolusStateModel

* refactor code and let add insulin button be disabled if maxBolus is exceeded

* remove unused variable
polscm32 2 лет назад
Родитель
Сommit
b8ea284d7c

+ 0 - 28
FreeAPS/Sources/Modules/Bolus/BolusStateModel.swift

@@ -73,8 +73,6 @@ extension Bolus {
             fattyMeals = settings.settings.fattyMeals
             fattyMealFactor = settings.settings.fattyMealFactor
 
-            // get carb ratio entry schedule
-
             if waitForSuggestionInitial {
                 apsManager.determineBasal()
                     .receive(on: DispatchQueue.main)
@@ -173,32 +171,6 @@ extension Bolus {
                 .store(in: &lifetime)
         }
 
-        func addWithoutBolus() {
-            guard amount > 0 else {
-                showModal(for: nil)
-                return
-            }
-            amount = min(amount, maxBolus * 3)
-
-            pumpHistoryStorage.storeEvents(
-                [
-                    PumpHistoryEvent(
-                        id: UUID().uuidString,
-                        type: .bolus,
-                        timestamp: Date(),
-                        amount: amount,
-                        duration: nil,
-                        durationMin: nil,
-                        rate: nil,
-                        temp: nil,
-                        carbInput: nil,
-                        isExternal: true
-                    )
-                ]
-            )
-            showModal(for: nil)
-        }
-
         func setupInsulinRequired() {
             DispatchQueue.main.async {
                 self.insulinRequired = self.provider.suggestion?.insulinReq ?? 0

+ 37 - 10
FreeAPS/Sources/Modules/Bolus/View/AlternativeBolusCalcRootView.swift

@@ -9,6 +9,7 @@ extension Bolus {
         @ObservedObject var state: StateModel
 
         @State private var showInfo = false
+        @State private var exceededMaxBolus = false
         @State var insulinCalculated: Decimal = 0
 
         @Environment(\.colorScheme) var colorScheme
@@ -136,7 +137,14 @@ extension Bolus {
                                     autofocus: false,
                                     cleanInput: true
                                 )
-                                Text(!(state.amount > state.maxBolus) ? "U" : "😵").foregroundColor(.secondary)
+                                Text(exceededMaxBolus ? "😵" : " U").foregroundColor(.secondary)
+                            }
+                            .onChange(of: state.amount) { newValue in
+                                if newValue > state.maxBolus {
+                                    exceededMaxBolus = true
+                                } else {
+                                    exceededMaxBolus = false
+                                }
                             }
                         }
                     }
@@ -144,15 +152,21 @@ extension Bolus {
                 header: { Text("Bolus") }
 
                 Section {
-                    Button(action: {
-                        state.add()
-                    }) {
-                        Text(!(state.amount > state.maxBolus) ? "Enact bolus" : "Max Bolus exceeded!")
-                            .frame(maxWidth: .infinity, alignment: .center)
+                    if state.amount == 0 {
+                        Button { state.showModal(for: nil) }
+                        label: { Text("Continue without bolus") }.frame(maxWidth: .infinity, alignment: .center)
+                    } else {
+                        Button(action: {
+                            state.add()
+                        }) {
+                            Text(exceededMaxBolus ? "Max Bolus exceeded!" : "Enact bolus")
+                                .frame(maxWidth: .infinity, alignment: .center)
+                        }
+                        .foregroundColor(exceededMaxBolus ? .loopRed : .accentColor)
+                        .disabled(
+                            state.amount <= 0 || state.amount > state.maxBolus
+                        )
                     }
-                    .disabled(
-                        state.amount <= 0 || state.amount > state.maxBolus
-                    )
                 }
                 .onAppear {
                     configureView {
@@ -387,13 +401,26 @@ extension Bolus {
                             .foregroundColor(.secondary)
                     }
                     .padding()
+
+                    if exceededMaxBolus {
+                        HStack {
+                            let maxBolus = state.maxBolus
+                            let maxBolusFormatted = maxBolus.formatted()
+                            Text("Your entered amount was limited by your max Bolus setting of \(maxBolusFormatted)\(unit)!")
+                        }
+                        .padding()
+                        .fontWeight(.semibold)
+                        .foregroundStyle(Color.loopRed)
+                    }
                 }
                 .padding(.top, 10)
                 .padding(.bottom, 15)
 
                 // Hide button
                 VStack {
-                    Button { showInfo = false }
+                    Button {
+                        showInfo = false
+                    }
                     label: {
                         Text("OK")
                     }