From 8d70c0cdb5f21676c2ecba83206a07bb54b5f675 Mon Sep 17 00:00:00 2001 From: Victor Gerbrands Date: Wed, 10 May 2023 16:47:59 +0200 Subject: [PATCH] feat: add categories and menus --- app/search/[collection]/page.tsx | 8 ++- app/sitemap.ts | 4 +- components/carousel.tsx | 4 +- components/grid/three-items.tsx | 4 +- components/layout/footer.tsx | 4 +- components/layout/navbar/index.tsx | 4 +- components/layout/search/collections.tsx | 4 +- lib/medusa/index.ts | 92 +++++++++++++++++------- lib/medusa/types.ts | 5 +- 9 files changed, 88 insertions(+), 41 deletions(-) diff --git a/app/search/[collection]/page.tsx b/app/search/[collection]/page.tsx index 60f73f280..85d7726fc 100644 --- a/app/search/[collection]/page.tsx +++ b/app/search/[collection]/page.tsx @@ -1,4 +1,4 @@ -import { getCollection, getCollectionProducts } from 'lib/medusa'; +import { getCategory, getCategoryProducts } from 'lib/medusa'; import { Metadata } from 'next'; import { notFound } from 'next/navigation'; @@ -12,7 +12,8 @@ export async function generateMetadata({ }: { params: { collection: string }; }): Promise { - const collection = await getCollection(params.collection); + console.log({ params }); + const collection = await getCategory(params.collection); if (!collection) return notFound(); @@ -33,7 +34,8 @@ export async function generateMetadata({ } export default async function CategoryPage({ params }: { params: { collection: string } }) { - const products = await getCollectionProducts(params.collection); + console.log({ collection: params.collection }); + const products = await getCategoryProducts(params.collection); return (
diff --git a/app/sitemap.ts b/app/sitemap.ts index f2789dba2..5c079a789 100644 --- a/app/sitemap.ts +++ b/app/sitemap.ts @@ -1,4 +1,4 @@ -import { getCollections, getProducts } from 'lib/medusa'; +import { getCategories, getProducts } from 'lib/medusa'; import { MetadataRoute } from 'next'; const baseUrl = process.env.NEXT_PUBLIC_VERCEL_URL @@ -11,7 +11,7 @@ export default async function sitemap(): Promise ({ url: `${baseUrl}${collection.path}`, lastModified: collection.updatedAt diff --git a/components/carousel.tsx b/components/carousel.tsx index a1ddcfda7..669ef15f1 100644 --- a/components/carousel.tsx +++ b/components/carousel.tsx @@ -1,10 +1,10 @@ -import { getCollectionProducts } from 'lib/medusa'; +import { getCategoryProducts } from 'lib/medusa'; import Image from 'next/image'; import Link from 'next/link'; export async function Carousel() { // Collections that start with `hidden-*` are hidden from the search page. - const products = await getCollectionProducts('hidden-homepage-carousel'); + const products = await getCategoryProducts('hidden-homepage-carousel'); if (!products?.length) return null; diff --git a/components/grid/three-items.tsx b/components/grid/three-items.tsx index 8bbf671e6..1cc93b271 100644 --- a/components/grid/three-items.tsx +++ b/components/grid/three-items.tsx @@ -1,5 +1,5 @@ import { GridTileImage } from 'components/grid/tile'; -import { getCollectionProducts } from 'lib/medusa'; +import { getCategoryProducts } from 'lib/medusa'; import type { Product } from 'lib/medusa/types'; import Link from 'next/link'; @@ -37,7 +37,7 @@ function ThreeItemGridItem({ export async function ThreeItemGrid() { // Collections that start with `hidden-*` are hidden from the search page. - const homepageItems = await getCollectionProducts('hidden-homepage-featured-items'); + const homepageItems = await getCategoryProducts('hidden-homepage-featured-items'); if (!homepageItems[0] || !homepageItems[1] || !homepageItems[2]) return null; diff --git a/components/layout/footer.tsx b/components/layout/footer.tsx index d9d8afb7e..e6a68febd 100644 --- a/components/layout/footer.tsx +++ b/components/layout/footer.tsx @@ -3,6 +3,7 @@ import Link from 'next/link'; import GitHubIcon from 'components/icons/github'; import LogoIcon from 'components/icons/logo'; import VercelIcon from 'components/icons/vercel'; +import { getMenu } from 'lib/medusa'; import { Menu } from 'lib/medusa/types'; const { SITE_NAME } = process.env; @@ -10,8 +11,7 @@ const { SITE_NAME } = process.env; export default async function Footer() { const currentYear = new Date().getFullYear(); const copyrightDate = 2023 + (currentYear > 2023 ? `-${currentYear}` : ''); - // const menu = await getMenu('next-js-frontend-footer-menu'); - const menu: any[] = []; + const menu = await getMenu('next-js-frontend-footer-menu'); return (