mirror of
https://github.com/rjNemo/meal_planner
synced 2026-06-06 10:36:43 +00:00
feat: Enhance categories page with improved error handling and card UI
This commit is contained in:
parent
85481b5f31
commit
d75d292b2a
1 changed files with 26 additions and 21 deletions
|
|
@ -1,5 +1,12 @@
|
|||
<script setup lang="ts">
|
||||
const { data: categories, status, error } = useCategories();
|
||||
|
||||
if (error.value) {
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
message: error.value.message,
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
|
@ -10,34 +17,32 @@ const { data: categories, status, error } = useCategories();
|
|||
<span class="loading loading-spinner loading-lg text-primary" />
|
||||
</div>
|
||||
|
||||
<div v-else-if="error" class="alert alert-error my-8 flex-col items-center">
|
||||
<div class="flex items-center">
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
class="stroke-current shrink-0 h-6 w-6"
|
||||
fill="none"
|
||||
viewBox="0 0 24 24"
|
||||
>
|
||||
<path
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
stroke-width="2"
|
||||
d="M10 14l2-2m0 0l2-2m-2 2l-2-2m2 2l2 2m7-2a9 9 0 11-18 0 9 9 0 0118 0z"
|
||||
/>
|
||||
</svg>
|
||||
<span>Failed to load categories</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div
|
||||
v-else-if="categories?.length > 0"
|
||||
class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6 my-8"
|
||||
>
|
||||
<category-card
|
||||
<div
|
||||
v-for="category in categories"
|
||||
:key="category.strCategory"
|
||||
:category="category"
|
||||
/>
|
||||
class="card bg-base-100 shadow-xl"
|
||||
>
|
||||
<figure>
|
||||
<img :src="category.strCategoryThumb" :alt="category.strCategory" />
|
||||
</figure>
|
||||
<div class="card-body">
|
||||
<h2 class="card-title">{{ category.strCategory }}</h2>
|
||||
<p>{{ category.strCategoryDescription }}</p>
|
||||
<div class="card-actions justify-end">
|
||||
<nuxt-link
|
||||
:to="`/category/${category.strCategory}`"
|
||||
class="btn btn-primary"
|
||||
>
|
||||
View Recipes
|
||||
</nuxt-link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="alert alert-info my-8 flex-col items-center">
|
||||
|
|
|
|||
Loading…
Reference in a new issue