Fixed another duplicate person bug
This commit is contained in:
parent
d175490c55
commit
f2a2daca6f
1 changed files with 10 additions and 8 deletions
|
|
@ -43,6 +43,12 @@ import DatePicker from './DatePicker.vue';
|
||||||
import EditableIngredientsPanel from '../ingredients/EditableIngredientsPanel.vue';
|
import EditableIngredientsPanel from '../ingredients/EditableIngredientsPanel.vue';
|
||||||
import PersonList from './PersonList.vue';
|
import PersonList from './PersonList.vue';
|
||||||
|
|
||||||
|
function addPersonIfNotExists(list, person) {
|
||||||
|
if (!list.find(p => p.id === person.id)) {
|
||||||
|
list.push(person);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: ['id'],
|
props: ['id'],
|
||||||
components: { RecipeSearchBox, DatePicker, RecipeCard, EditableIngredientsPanel, PersonList },
|
components: { RecipeSearchBox, DatePicker, RecipeCard, EditableIngredientsPanel, PersonList },
|
||||||
|
|
@ -70,11 +76,11 @@ export default {
|
||||||
recipe = await data.getRecipe(recipe.id);
|
recipe = await data.getRecipe(recipe.id);
|
||||||
|
|
||||||
if (recipe.created_by) {
|
if (recipe.created_by) {
|
||||||
this.meal.chefs.push(recipe.created_by);
|
addPersonIfNotExists(this.meal.chefs, recipe.created_by);
|
||||||
this.meal.consumers.push(recipe.created_by);
|
addPersonIfNotExists(this.meal.consumers, recipe.created_by);
|
||||||
|
|
||||||
if (this.meal.cleanup.length === 0) {
|
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);
|
this.meal[list] = this.meal[list].filter(p => p.id !== person.id);
|
||||||
},
|
},
|
||||||
addPerson(list, person) {
|
addPerson(list, person) {
|
||||||
if (this.meal[list].find(p => p.id === person.id)) {
|
addPersonIfNotExists(this.meal[list], person);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.meal[list].push(person);
|
|
||||||
},
|
},
|
||||||
async saveMeal() {
|
async saveMeal() {
|
||||||
const meal = await data.saveMeal(this.meal);
|
const meal = await data.saveMeal(this.meal);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue