From ae9d6d7c4b02d4eb8a2e97b68bdc46b455bd8c09 Mon Sep 17 00:00:00 2001 From: andr-ew Date: Wed, 21 Jun 2023 16:42:53 -0500 Subject: [PATCH] app/page: products list markup, prices --- app/page.js | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/app/page.js b/app/page.js index 2ae11afe1..309de48bb 100644 --- a/app/page.js +++ b/app/page.js @@ -22,6 +22,36 @@ const formatPriceRange = ({ maxVariantPrice, minVariantPrice }) => { } }; +const PriceRanges = ({ priceRange, compareAtPriceRange, availableForSale }) => { + const onSale = + (compareAtPriceRange?.minVariantPrice?.amount ?? 0) > + (priceRange?.minVariantPrice?.amount ?? 0) || + (compareAtPriceRange?.maxVariantPrice?.amount ?? 0) > + (priceRange?.maxVariantPrice?.amount ?? 0); + const isForSale = (priceRange?.maxVariantPrice?.amount ?? 0) > 0; + + return ( +

+ {availableForSale ? ( + isForSale && ( + <> + <> + {onSale && ( + + {formatPriceRange(compareAtPriceRange)}{' '} + + )} + + {formatPriceRange(priceRange)} + + ) + ) : ( + Sold Out + )} +

+ ); +}; + export async function HomeProduct({ product }) { const featuredImage = product?.images?.[0]; const collections = product?.collections?.nodes; @@ -40,13 +70,7 @@ export async function HomeProduct({ product }) { ?.map(collection => collection?.title) .join(', ')})`}

)} - {product?.availableForSale ? ( - (product?.priceRange?.maxVariantPrice?.amount ?? 0) > 0 && ( -

{formatPriceRange(product.priceRange)}

- ) - ) : ( -

Sold Out

- )} + ); } @@ -57,8 +81,13 @@ export default async function HomePage() { collection, }); - console.log({ collection, products }); - // console.log({ price: products[0].priceRange, tile: products[0].title }); + // console.log({ collection, products }); + // const num = 4; + // console.log({ + // price: products[num].priceRange, + // compareAt: products[num].compareAtPriceRange, + // title: products[num].title, + // }); return ( <>