diff --git a/src/app/[country]/[locale]/(storefront)/c/[...permalink]/CategoryBanner.tsx b/src/app/[country]/[locale]/(storefront)/c/[...permalink]/CategoryBanner.tsx new file mode 100644 index 00000000..ffe4b8e4 --- /dev/null +++ b/src/app/[country]/[locale]/(storefront)/c/[...permalink]/CategoryBanner.tsx @@ -0,0 +1,69 @@ +import type { Category } from "@spree/sdk"; +import { cacheLife, cacheTag } from "next/cache"; +import Link from "next/link"; +import { Breadcrumbs } from "@/components/navigation/Breadcrumbs"; + +interface CategoryBannerProps { + category: Category; + basePath: string; + locale: string; +} + +export async function CategoryBanner({ + category, + basePath, + locale, +}: CategoryBannerProps) { + "use cache: remote"; + cacheLife("minutes"); + cacheTag("category-banner"); + + return ( + <> +
+
+ + +
+

+ {category.name} +

+
+ + {/* Description */} + {category.description && ( +

{category.description}

+ )} +
+
+ + {/* Subcategories */} + {category.children && category.children.length > 0 && ( +
+
+ {category.children.map((child) => ( + + {child.name} + + ))} +
+
+ )} + + ); +} diff --git a/src/app/[country]/[locale]/(storefront)/c/[...permalink]/page.tsx b/src/app/[country]/[locale]/(storefront)/c/[...permalink]/page.tsx index c51d9c21..dad91b33 100644 --- a/src/app/[country]/[locale]/(storefront)/c/[...permalink]/page.tsx +++ b/src/app/[country]/[locale]/(storefront)/c/[...permalink]/page.tsx @@ -7,6 +7,7 @@ import { getCategory } from "@/lib/data/categories"; import { generateCategoryMetadata } from "@/lib/metadata/category"; import { buildBreadcrumbJsonLd } from "@/lib/seo"; import { getStoreUrl } from "@/lib/store"; +import { CategoryBanner } from "./CategoryBanner"; import { CategoryProductsContent } from "./CategoryProductsContent"; interface CategoryPageProps { @@ -51,50 +52,7 @@ export default async function CategoryPage({ params }: CategoryPageProps) { )} -
-
- - -
-

- {category.name} -

-
- - {/* Description */} - {category.description && ( -

{category.description}

- )} -
-
- - {/* Subcategories */} - {category.children && category.children.length > 0 && ( -
-
- {category.children.map((child) => ( - - {child.name} - - ))} -
-
- )} +
{/* Products */} diff --git a/src/lib/data/categories.ts b/src/lib/data/categories.ts index f2016e16..0d65cb07 100644 --- a/src/lib/data/categories.ts +++ b/src/lib/data/categories.ts @@ -19,12 +19,23 @@ export async function getCategories(params?: CategoryListParams) { return cachedListCategories(params, options); } +async function cachedGetCategory( + idOrPermalink: string, + params: { expand?: string[] } | undefined, + options: { locale?: string; country?: string }, +) { + "use cache: remote"; + cacheLife("minutes"); + cacheTag("category"); + return getClient().categories.get(idOrPermalink, params, options); +} + export async function getCategory( idOrPermalink: string, - params?: CategoryListParams, + params?: { expand?: string[] }, ) { const options = await getLocaleOptions(); - return getClient().categories.get(idOrPermalink, params, options); + return cachedGetCategory(idOrPermalink, params, options); } export async function getCategoryProducts(