diff --git a/composables/useRecipe.ts b/composables/useRecipe.ts index 376944c..bf57fcc 100644 --- a/composables/useRecipe.ts +++ b/composables/useRecipe.ts @@ -8,12 +8,32 @@ type Recipe = { instructions: string; }; -export default async function () { +type Keyword = "random" | "filter" | "lookup" | "search"; +export default async function (keyword: Keyword, param?: string) { const { data, pending, error } = await useAsyncData( - "random", + keyword, async () => { const config = useRuntimeConfig(); - return await $fetch(`${config.apiUrl}random.php`); + + let url = ""; + + switch (keyword) { + case "random": + url = `${config.apiUrl}random.php`; + break; + case "filter": + url = ""; + break; + case "lookup": + url = `${config.apiUrl}${keyword}.php?i=${param}`; + break; + case "search": + url = ""; + break; + default: + throw Error("unexpected URI parameters"); + } + return await $fetch(url); }, { lazy: true }, ); diff --git a/pages/[id].vue b/pages/[id].vue new file mode 100644 index 0000000..7726872 --- /dev/null +++ b/pages/[id].vue @@ -0,0 +1,28 @@ + + + + Loading + Failed: {{ error }} + + + + + + + + + + Instructions + {{ recipe.instructions }} + + + diff --git a/pages/random.vue b/pages/random.vue index 575d4d2..ab68a1a 100644 --- a/pages/random.vue +++ b/pages/random.vue @@ -1,5 +1,11 @@ @@ -19,7 +25,7 @@ const { recipe, pending, error } = await useRecipe(); - + Instructions {{ recipe.instructions }}
{{ recipe.instructions }}