mirror of
https://github.com/vercel/commerce.git
synced 2025-05-15 05:56:59 +00:00
app/page: products list markup
This commit is contained in:
parent
3b696400ae
commit
f54c0cfe65
47
app/page.js
47
app/page.js
@ -1,3 +1,46 @@
|
|||||||
export default function Page() {
|
import Link from 'next/link';
|
||||||
return <h1>Hello, Next.js!</h1>;
|
import Image from 'next/image';
|
||||||
|
|
||||||
|
import { getCollectionProducts } from 'lib/shopify';
|
||||||
|
|
||||||
|
export async function HomeProduct({ product }) {
|
||||||
|
const featuredImage = product?.images?.[0];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Link href={`/${product?.handle}`}>
|
||||||
|
<Image
|
||||||
|
src={featuredImage?.url}
|
||||||
|
alt={featuredImage?.altText}
|
||||||
|
width={featuredImage?.width}
|
||||||
|
height={featuredImage?.height}
|
||||||
|
/>
|
||||||
|
<p>{product?.title}</p>
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default async function HomePage() {
|
||||||
|
const collection = process.env.HOMEPAGE_COLLECTION;
|
||||||
|
const products = await getCollectionProducts({
|
||||||
|
collection,
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log({ collection, products });
|
||||||
|
// console.log({ img: products[1].images });
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
{products.length === 0 ? (
|
||||||
|
<p>{`No products found`}</p>
|
||||||
|
) : (
|
||||||
|
<ul>
|
||||||
|
{products.map(product => (
|
||||||
|
<li key={product?.handle}>
|
||||||
|
<HomeProduct {...{ product }} />
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user