From 6dffeb5766a0290552882ddeccb07f5cc153c91f Mon Sep 17 00:00:00 2001 From: Ruidy Date: Sat, 14 Dec 2024 13:19:28 +0100 Subject: [PATCH] improve search results displays --- components/app/footer.vue | 4 +- components/app/navbar.vue | 2 +- components/recipe/search.vue | 4 +- pages/search.vue | 86 +++++++++++++++++----------------- server/trpc/routers/recipes.ts | 5 +- 5 files changed, 48 insertions(+), 53 deletions(-) diff --git a/components/app/footer.vue b/components/app/footer.vue index f0a873d..3107bce 100644 --- a/components/app/footer.vue +++ b/components/app/footer.vue @@ -18,7 +18,7 @@ > + /> + /> diff --git a/components/app/navbar.vue b/components/app/navbar.vue index d80ab8d..245cfcf 100644 --- a/components/app/navbar.vue +++ b/components/app/navbar.vue @@ -76,7 +76,7 @@ if (route.path === "/search") { diff --git a/components/recipe/search.vue b/components/recipe/search.vue index 0aaff94..32b99a3 100644 --- a/components/recipe/search.vue +++ b/components/recipe/search.vue @@ -3,14 +3,14 @@ class="input input-bordered input-primary flex items-center gap-2 container mx-auto px-4 lg:px-8 my-4" > + > K diff --git a/pages/search.vue b/pages/search.vue index 056514b..67002bc 100644 --- a/pages/search.vue +++ b/pages/search.vue @@ -4,45 +4,38 @@ import type { Recipe } from "~/types/recipe"; const route = useRoute(); const searchQuery = computed(() => route.query.q as string); const searchResults = ref([]); -const { data, status, error, execute } = await useRecipeSearch( - searchQuery.value || "", -); + +const { data, status, error } = await useRecipeSearch(searchQuery.value || ""); +if (error.value) { + throw createError({ + statusCode: 500, + message: error.value.message, + }); +} searchResults.value = data.value; watch(searchQuery, async (newQuery) => { - const { data, status, error, execute } = await useRecipeSearch( - newQuery.trim(), - ); + const { data, error } = await useRecipeSearch(newQuery.trim()); + if (error.value) { + throw createError({ + statusCode: 500, + message: error.value.message, + }); + } + searchResults.value = data.value; }); diff --git a/server/trpc/routers/recipes.ts b/server/trpc/routers/recipes.ts index 254c2a9..9103a2c 100644 --- a/server/trpc/routers/recipes.ts +++ b/server/trpc/routers/recipes.ts @@ -53,10 +53,7 @@ export const recipeRouter = router({ new URL(`search.php?s=${input}`, apiUrl).href, ); if (!data?.meals) { - throw createError({ - statusCode: 404, - statusMessage: "Recipe not found", - }); + return []; } const recipes = parseRecipeData(data); return recipes;