diff --git a/components/recipe/ingredients.vue b/components/recipe/ingredients.vue new file mode 100644 index 0000000..08a63ce --- /dev/null +++ b/components/recipe/ingredients.vue @@ -0,0 +1,26 @@ + + + diff --git a/composables/useRecipe.ts b/composables/useRecipe.ts index 2f7e94c..114967c 100644 --- a/composables/useRecipe.ts +++ b/composables/useRecipe.ts @@ -4,6 +4,7 @@ type Recipe = { videoUrl: string; category: string; origin: string; + ingredients: { name: string; quantitiy: number }; }; export default async function () { @@ -18,12 +19,25 @@ export default async function () { 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({ title: tmp.value.strMeal, pictureUrl: tmp.value.strMealThumb, videoUrl: tmp.value.strYoutube, category: tmp.value.strCategory, origin: tmp.value.strArea, + ingredients: names.map((name, i) => ({ name, quantity: quantities[i] })), }); return { diff --git a/pages/random.vue b/pages/random.vue index 06bff02..3c10d8a 100644 --- a/pages/random.vue +++ b/pages/random.vue @@ -6,14 +6,18 @@ const { recipe, pending, error } = await useRecipe();
Loading
Failed: {{ error }}
-
- +
+
+ +
+ +