Bläddra i källkod

Add preset to meal on selection #254

Deniz Cengiz 1 år sedan
förälder
incheckning
6f6d90e3b8

+ 9 - 0
FreeAPS/Sources/Modules/Treatments/View/MealPreset/MealPresetView.swift

@@ -115,6 +115,15 @@ struct MealPresetView: View {
                         Text(preset.dish ?? "").tag(preset as MealPresetStored?)
                     }
                 }
+                .onChange(of: state.selection) {
+                    carbs += ((state.selection?.carbs ?? 0) as NSDecimalNumber) as Decimal
+                    if state.useFPUconversion {
+                        fat += ((state.selection?.fat ?? 0) as NSDecimalNumber) as Decimal
+                        protein += ((state.selection?.protein ?? 0) as NSDecimalNumber) as Decimal
+                    }
+
+                    state.addPresetToNewMeal()
+                }
                 .labelsHidden()
                 .frame(maxWidth: .infinity, alignment: .center)
                 if state.selection != nil {