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);