2024-01-13 02:00:15 +00:00
|
|
|
<template>
|
2025-10-18 02:08:22 +00:00
|
|
|
<div class="ingredient-item">
|
|
|
|
|
<p>
|
|
|
|
|
<input
|
|
|
|
|
v-model="ingredientText"
|
|
|
|
|
@keyup.enter="updateIngredient"
|
|
|
|
|
@blur="updateIngredient"
|
|
|
|
|
placeholder="Enter an ingredient"
|
|
|
|
|
/>
|
|
|
|
|
<input
|
|
|
|
|
v-model="productLink"
|
|
|
|
|
v-if="ingredient.line"
|
|
|
|
|
class="product-link-input"
|
|
|
|
|
placeholder="Enter product link"
|
|
|
|
|
@keyup.enter="updateProductLink"
|
|
|
|
|
@blur="updateProductLink"
|
|
|
|
|
/>
|
|
|
|
|
</p>
|
|
|
|
|
<p v-if="ingredient.line">
|
|
|
|
|
<!-- Single line parse results -->
|
|
|
|
|
<compact-parsed-ingredient :ingredient="ingredient" />
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
2024-01-13 02:00:15 +00:00
|
|
|
</template>
|
|
|
|
|
|
2025-10-18 02:39:25 +00:00
|
|
|
<script setup>
|
|
|
|
|
import { ref, watch } from 'vue'
|
2025-10-18 02:08:22 +00:00
|
|
|
import CompactParsedIngredient from './CompactParsedIngredient.vue'
|
2024-01-13 02:00:15 +00:00
|
|
|
|
2025-10-18 02:39:25 +00:00
|
|
|
const props = defineProps({
|
|
|
|
|
ingredient: { type: Object, required: true },
|
|
|
|
|
})
|
|
|
|
|
const emit = defineEmits(['update-ingredient', 'update-product-link'])
|
|
|
|
|
|
|
|
|
|
const ingredientText = ref(props.ingredient?.line ?? '')
|
|
|
|
|
const productLink = ref(props.ingredient.product?.link ?? '')
|
|
|
|
|
|
|
|
|
|
watch(
|
|
|
|
|
() => props.ingredient,
|
|
|
|
|
(newIngredient) => {
|
|
|
|
|
ingredientText.value = newIngredient?.line ?? ''
|
|
|
|
|
productLink.value = newIngredient?.product?.link ?? ''
|
2025-10-18 02:08:22 +00:00
|
|
|
},
|
2025-10-18 02:39:25 +00:00
|
|
|
{ deep: true }
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
function updateIngredient() {
|
|
|
|
|
if (ingredientText.value != props.ingredient.line) {
|
|
|
|
|
emit('update-ingredient', props.ingredient, ingredientText.value)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function updateProductLink() {
|
|
|
|
|
if (productLink.value && productLink.value != props.ingredient.product?.link) {
|
|
|
|
|
emit('update-product-link', props.ingredient, productLink.value)
|
|
|
|
|
}
|
2025-10-18 02:08:22 +00:00
|
|
|
}
|
2024-01-13 02:00:15 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
2024-01-17 06:37:57 +00:00
|
|
|
input {
|
2025-10-18 02:08:22 +00:00
|
|
|
border: 0;
|
|
|
|
|
font-size: larger;
|
|
|
|
|
border-bottom: 1px solid #ccc;
|
|
|
|
|
border-left: 1px solid #ccc;
|
|
|
|
|
width: 100%;
|
|
|
|
|
padding: 0.5vh;
|
2024-01-13 02:00:15 +00:00
|
|
|
}
|
|
|
|
|
|
2024-01-14 01:46:45 +00:00
|
|
|
.product-link-input {
|
2025-10-18 02:08:22 +00:00
|
|
|
color: #777;
|
|
|
|
|
margin-top: 0.5vh;
|
2024-01-13 02:00:15 +00:00
|
|
|
}
|
|
|
|
|
</style>
|