mirror of
https://github.com/rjNemo/meal_planner
synced 2026-06-12 13:26:45 +00:00
ingredients list
This commit is contained in:
parent
bd5fe9be95
commit
ec19f99492
3 changed files with 52 additions and 8 deletions
26
components/recipe/ingredients.vue
Normal file
26
components/recipe/ingredients.vue
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
defineProps<{
|
||||||
|
ingredients: { name: string; quantity: number }[];
|
||||||
|
}>();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div class="overflow-x-auto">
|
||||||
|
<table class="table table-s table-pin-rows table-pin-cols">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th></th>
|
||||||
|
<td>Ingredient</td>
|
||||||
|
<td>Quantity</td>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
<tr v-for="(ingredient, i) in ingredients">
|
||||||
|
<th>{{ i + 1 }}</th>
|
||||||
|
<td>{{ ingredient.name }}</td>
|
||||||
|
<td>{{ ingredient.quantity }}</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
@ -4,6 +4,7 @@ type Recipe = {
|
||||||
videoUrl: string;
|
videoUrl: string;
|
||||||
category: string;
|
category: string;
|
||||||
origin: string;
|
origin: string;
|
||||||
|
ingredients: { name: string; quantitiy: number };
|
||||||
};
|
};
|
||||||
|
|
||||||
export default async function () {
|
export default async function () {
|
||||||
|
|
@ -18,12 +19,25 @@ export default async function () {
|
||||||
|
|
||||||
const tmp = computed(() => data.value?.meals?.[0]);
|
const tmp = computed(() => data.value?.meals?.[0]);
|
||||||
|
|
||||||
|
let names = [];
|
||||||
|
let quantities = [];
|
||||||
|
let i = 0;
|
||||||
|
for (const [k, v] of Object.entries(tmp.value)) {
|
||||||
|
if (k.startsWith("strIngredient") && !!v) {
|
||||||
|
names.push(v);
|
||||||
|
} else if (k.startsWith("strMeasure") && !!v) {
|
||||||
|
quantities.push(v);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
const recipe = reactive<Recipe>({
|
const recipe = reactive<Recipe>({
|
||||||
title: tmp.value.strMeal,
|
title: tmp.value.strMeal,
|
||||||
pictureUrl: tmp.value.strMealThumb,
|
pictureUrl: tmp.value.strMealThumb,
|
||||||
videoUrl: tmp.value.strYoutube,
|
videoUrl: tmp.value.strYoutube,
|
||||||
category: tmp.value.strCategory,
|
category: tmp.value.strCategory,
|
||||||
origin: tmp.value.strArea,
|
origin: tmp.value.strArea,
|
||||||
|
ingredients: names.map((name, i) => ({ name, quantity: quantities[i] })),
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -6,14 +6,18 @@ const { recipe, pending, error } = await useRecipe();
|
||||||
<div v-if="pending">Loading</div>
|
<div v-if="pending">Loading</div>
|
||||||
<div v-else-if="error">Failed: {{ error }}</div>
|
<div v-else-if="error">Failed: {{ error }}</div>
|
||||||
<section v-else>
|
<section v-else>
|
||||||
<div class="card w-96 bg-base-100 shadow-xl">
|
<div class="lg:flex space-y-4 lg:justify-evenly py-4">
|
||||||
<RecipeCard
|
<div class="card w-96 bg-base-100 shadow-xl mx-auto lg:mx-2">
|
||||||
:title="recipe.title"
|
<RecipeCard
|
||||||
:picture-url="recipe.pictureUrl"
|
:title="recipe.title"
|
||||||
:video-url="recipe.videoUrl"
|
:picture-url="recipe.pictureUrl"
|
||||||
:category="recipe.category"
|
:video-url="recipe.videoUrl"
|
||||||
:origin="recipe.origin"
|
:category="recipe.category"
|
||||||
/>
|
:origin="recipe.origin"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<RecipeIngredients :ingredients="recipe.ingredients" />
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue