munch-ease-frontend/src/components/IngredientAddBox.vue

68 lines
1.6 KiB
Vue
Raw Normal View History

2024-01-14 02:12:19 +00:00
<template>
2024-01-14 06:20:21 +00:00
<div class="ingredient-add-box">
<p class="ingredient-line">
<ingredient-line :ingredient="ingredient"
:show-expanded="true"
@update-ingredient="updateIngredient"
@update-product-link="updateProduct"
@delete-item="deleteIngredient" />
</p>
<button @click="addIngredient(ingredient)">Add</button>
2024-01-14 02:12:19 +00:00
</div>
</template>
<script>
import IngredientLine from './IngredientLine.vue';
import data from '@/data.js'
export default {
name: 'IngredientAddBox',
components: { IngredientLine },
data() {
return {
ingredient: {
name: '',
quantity: '',
unit: '',
2024-01-17 06:03:11 +00:00
link: ''
2024-01-14 02:12:19 +00:00
},
}
},
methods: {
addIngredient() {
this.$emit('add-ingredient', this.ingredient);
this.ingredient = {
name: '',
quantity: '',
unit: '',
2024-01-14 06:20:21 +00:00
link: ''
2024-01-14 02:12:19 +00:00
};
},
updateProduct(ingredient, product_link) {
data.parseProduct(ingredient, product_link).then(product => {
2024-01-17 06:03:11 +00:00
this.ingredient.product = product;
this.ingredient.product_link = product.link;
2024-01-14 02:12:19 +00:00
});
},
updateIngredient(ingredient, line) {
2024-01-17 06:03:11 +00:00
data.parseIngredients([line]).then(newIngredients => {
this.ingredient = newIngredients[0];
2024-01-14 02:12:19 +00:00
});
},
}
}
</script>
<style scoped>
2024-01-14 06:20:21 +00:00
.ingredient-add-box {
display: flex;
flex-direction: row;
}
.ingredient-line {
flex: 1;
}
2024-01-14 02:12:19 +00:00
</style>