diff --git a/composables/useCategoryRecipes.ts b/composables/useCategoryRecipes.ts new file mode 100644 index 0000000..fc56f20 --- /dev/null +++ b/composables/useCategoryRecipes.ts @@ -0,0 +1,4 @@ +export function useCategoryRecipes(category: string) { + const { $client } = useNuxtApp(); + return $client.recipesByCategory.useQuery(category); +} diff --git a/pages/category/[name].vue b/pages/category/[name].vue new file mode 100644 index 0000000..0701ba2 --- /dev/null +++ b/pages/category/[name].vue @@ -0,0 +1,69 @@ + + + + + + + + {{ category.value.name }} + + + + + + {{ category.value.description }} + + + + + + + + + + + + + {{ recipe.title }} + + + View Recipe + + + + + + + + No recipes found in this category. + + + + diff --git a/server/trpc/routers/recipes.ts b/server/trpc/routers/recipes.ts index b43426a..9e46e2e 100644 --- a/server/trpc/routers/recipes.ts +++ b/server/trpc/routers/recipes.ts @@ -13,6 +13,20 @@ type Category = { }; export const recipeRouter = router({ + recipesByCategory: publicProcedure + .input(z.string()) + .query(async ({ input }) => { + const data = await $fetch<{ meals: Meal[] }>( + new URL(`filter.php?c=${input}`, apiUrl).href, + ); + + if (!data?.meals) { + return []; + } + + const recipes = parseRecipeData(data); + return recipes; + }), recipeGet: publicProcedure .input( z.coerce
{{ category.value.description }}