From f2a2daca6f7253e72f28297d9889749573c48c41 Mon Sep 17 00:00:00 2001 From: jableader Date: Sun, 19 May 2024 22:40:32 +1000 Subject: [PATCH] Fixed another duplicate person bug --- src/components/meals/EditMealPage.vue | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/components/meals/EditMealPage.vue b/src/components/meals/EditMealPage.vue index a6308cc..75fecaf 100644 --- a/src/components/meals/EditMealPage.vue +++ b/src/components/meals/EditMealPage.vue @@ -43,6 +43,12 @@ import DatePicker from './DatePicker.vue'; import EditableIngredientsPanel from '../ingredients/EditableIngredientsPanel.vue'; import PersonList from './PersonList.vue'; +function addPersonIfNotExists(list, person) { + if (!list.find(p => p.id === person.id)) { + list.push(person); + } +} + export default { props: ['id'], components: { RecipeSearchBox, DatePicker, RecipeCard, EditableIngredientsPanel, PersonList }, @@ -70,11 +76,11 @@ export default { recipe = await data.getRecipe(recipe.id); if (recipe.created_by) { - this.meal.chefs.push(recipe.created_by); - this.meal.consumers.push(recipe.created_by); + addPersonIfNotExists(this.meal.chefs, recipe.created_by); + addPersonIfNotExists(this.meal.consumers, recipe.created_by); if (this.meal.cleanup.length === 0) { - this.meal.cleanup.push(recipe.created_by); + addPersonIfNotExists(this.meal.cleanup, recipe.created_by); } } @@ -99,11 +105,7 @@ export default { this.meal[list] = this.meal[list].filter(p => p.id !== person.id); }, addPerson(list, person) { - if (this.meal[list].find(p => p.id === person.id)) { - return; - } - - this.meal[list].push(person); + addPersonIfNotExists(this.meal[list], person); }, async saveMeal() { const meal = await data.saveMeal(this.meal);