2024-05-12 06:32:28 +00:00
|
|
|
<template>
|
|
|
|
|
|
|
|
|
|
<div>
|
2024-05-12 07:24:29 +00:00
|
|
|
<button v-if="editing" @click="$emit('on-add')">
|
|
|
|
|
<img class="icon" :src="require('@/assets/add-cart.svg')" /> <br />
|
|
|
|
|
Add Ingredient
|
|
|
|
|
</button>
|
|
|
|
|
<button @click="toggleEditing">
|
|
|
|
|
<span v-if="editing">
|
|
|
|
|
<img class="icon" :src="require('@/assets/edit-off.svg')" /> <br />
|
|
|
|
|
Done Editing
|
|
|
|
|
</span>
|
|
|
|
|
<span v-else>
|
|
|
|
|
<img class="icon" :src="require('@/assets/edit.svg')" /> <br />
|
|
|
|
|
Edit My List
|
|
|
|
|
</span>
|
|
|
|
|
</button>
|
2024-05-12 06:32:28 +00:00
|
|
|
<ul>
|
2024-05-12 07:24:29 +00:00
|
|
|
<li v-for="ingredient in ingredients" :key="ingredient">
|
2024-05-12 06:32:28 +00:00
|
|
|
<div v-if="editing">
|
2024-05-12 06:42:20 +00:00
|
|
|
<p class="ingredient-line">
|
|
|
|
|
<ingredient-line
|
|
|
|
|
:ingredient="ingredient"
|
|
|
|
|
@update-ingredient="updateIngredient"
|
|
|
|
|
@update-product-link="updateProduct" />
|
|
|
|
|
</p>
|
2024-05-12 06:32:28 +00:00
|
|
|
<button @click="$emit('on-delete', ingredient)">
|
|
|
|
|
<img class="icon" :src="require('@/assets/trash.svg')" />
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div v-else>
|
|
|
|
|
<compact-parsed-ingredient :ingredient="ingredient" />
|
|
|
|
|
</div>
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
2024-05-12 06:42:20 +00:00
|
|
|
<style scoped>
|
|
|
|
|
|
2024-05-12 06:32:28 +00:00
|
|
|
.icon {
|
2024-05-12 06:42:20 +00:00
|
|
|
width: 2em;
|
|
|
|
|
height: 2em;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ul {
|
|
|
|
|
padding: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
li {
|
|
|
|
|
list-style: none;
|
|
|
|
|
border: 1px solid #ccc;
|
|
|
|
|
border-radius: 5px;
|
|
|
|
|
padding: 5px;
|
2024-05-12 06:32:28 +00:00
|
|
|
}
|
2024-05-12 06:42:20 +00:00
|
|
|
|
|
|
|
|
li > div {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: row;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
width: 100%;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.ingredient-line {
|
|
|
|
|
flex: 1;
|
|
|
|
|
margin: 0;
|
|
|
|
|
margin-right: 1em;
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-12 06:32:28 +00:00
|
|
|
</style>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import data from '@/data.js'
|
|
|
|
|
import IngredientLine from './IngredientLine.vue'
|
|
|
|
|
import CompactParsedIngredient from './CompactParsedIngredient.vue'
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: 'EditableIngredientsPanel',
|
|
|
|
|
components: { IngredientLine, CompactParsedIngredient },
|
|
|
|
|
props: ['ingredients', 'editOnly'],
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
|
|
|
|
editing: this.editOnly ?? false
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
async updateProduct(ingredient, product_link) {
|
|
|
|
|
const product = await data.parseProduct(ingredient, product_link);
|
|
|
|
|
this.$emit('on-update-ingredient', ingredient, { ...ingredient, product });
|
|
|
|
|
},
|
|
|
|
|
async updateIngredient(ingredient, line) {
|
|
|
|
|
const newIngredients = await data.parseIngredients([line]);
|
|
|
|
|
this.$emit('on-update-ingredient', ingredient, newIngredients[0]);
|
|
|
|
|
},
|
2024-05-12 07:00:26 +00:00
|
|
|
toggleEditing() {
|
|
|
|
|
this.editing = !this.editing;
|
|
|
|
|
if (this.editing && !this.ingredients.length) {
|
|
|
|
|
this.$emit('on-add');
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-05-12 06:32:28 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
</script>
|