From e9dfda1e86bb1dda4050c6887b433542235d76d2 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Thu, 7 Jan 2021 11:58:00 -0300 Subject: [PATCH] Restored Index Agnostic --- .../ProductCard/FUTURE_ProductCard.tsx | 80 ++++++++++++------- components/ui/Marquee/Marquee.module.css | 11 +-- framework/types.d.ts | 29 +++---- pages/index.tsx | 52 +++++++----- 4 files changed, 101 insertions(+), 71 deletions(-) diff --git a/components/product/ProductCard/FUTURE_ProductCard.tsx b/components/product/ProductCard/FUTURE_ProductCard.tsx index 9ca615d90..604b91460 100644 --- a/components/product/ProductCard/FUTURE_ProductCard.tsx +++ b/components/product/ProductCard/FUTURE_ProductCard.tsx @@ -1,5 +1,6 @@ import { FC } from 'react' import cn from 'classnames' +import Link from 'next/link' import Image, { ImageProps } from 'next/image' import s from './ProductCard.module.css' // Restore Wishlist func @@ -13,44 +14,63 @@ interface Props { } const ProductCard: FC = ({ className, product, variant, imgProps }) => { - const firstImage = product.images[0] return ( - - {variant === 'slim' ? ( -
-
- - {product.name} - - {/* Image */} -
-
- ) : ( - <> -
-
-
-

- {product.name} -

- {product.price} + +
+ {variant === 'slim' ? ( +
+
+ + {product.name} +
-
-
- {firstImage.src && ( + {product.images[0] && ( {product.name} )}
- - )} -
+ ) : ( + <> +
+
+
+

+ {product.name} +

+ + {product.prices[0].value} +   + {product.prices[0].currencyCode} + +
+
+
+ {product.images[0] && ( + {product.name} + )} +
+ + )} + + ) } diff --git a/components/ui/Marquee/Marquee.module.css b/components/ui/Marquee/Marquee.module.css index 32601a54e..1fabc2ca8 100644 --- a/components/ui/Marquee/Marquee.module.css +++ b/components/ui/Marquee/Marquee.module.css @@ -1,15 +1,16 @@ .root { - @apply w-full; + @apply w-full relative; + height: 320px; min-width: 100%; } .container { @apply flex flex-row items-center; +} - & > * { - @apply flex-1 px-16 py-4; - width: 430px; - } +.container > * { + @apply relative flex-1 px-16 py-4 h-full; + min-height: 320px; } .primary { diff --git a/framework/types.d.ts b/framework/types.d.ts index de5deb080..4098e5c7e 100644 --- a/framework/types.d.ts +++ b/framework/types.d.ts @@ -1,25 +1,20 @@ +interface ProductImage { + url: string + alt?: string +} + interface Product { id: string | number name: string description: string - images: Image[] + images: ProductImage[] + prices: ProductPrice[] slug: string - price: string - variantId: string + path?: string } -interface Image { - src: string - alt?: string +interface ProductPrice { + value: number | string + currencyCode: 'USD' | 'ARS' + type?: 'price' | 'retail' | 'sale' | string } - -// interface NextImageProps { -// src: string -// width: number | string -// height: number | string -// layout?: 'fixed' | 'intrinsic' | 'responsive' | undefined -// priority?: boolean -// loading?: 'eager' | 'lazy' -// sizes?: string -// alt?: string -// } diff --git a/pages/index.tsx b/pages/index.tsx index 8406b333c..186da09f6 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -13,13 +13,23 @@ import getAllPages from '@framework/api/operations/get-all-pages' // Outputs from providers should already be normalized // TODO (bc) move this to the provider -function normalize(arr: any[]) { +function productsNormalizer(arr: any[]) { // Normalizes products arr response and flattens node edges return arr.map( ({ - node: { entityId: id, images, variants, productOptions, ...rest }, + node: { + entityId: id, + images, + variants, + productOptions, + prices, + path, + ...rest + }, }) => ({ id, + path, + slug: path.slice(1, -1), images: images.edges.map( ({ node: { urlOriginal, altText, ...rest } }: any) => ({ url: urlOriginal, @@ -29,6 +39,12 @@ function normalize(arr: any[]) { ), variants: variants.edges.map(({ node }: any) => node), productOptions: productOptions.edges.map(({ node }: any) => node), + prices: [ + { + value: prices.price.value, + currencyCode: prices.price.currencyCode, + }, + ], ...rest, }) ) @@ -46,10 +62,8 @@ export async function getStaticProps({ preview, }) - const products = normalize(rawProducts) - - // console.log(products) - + // Remove normalizer and send to framework provider. + const products = productsNormalizer(rawProducts) const { categories, brands } = await getSiteInfo({ config, preview }) const { pages } = await getAllPages({ config, preview }) @@ -83,11 +97,11 @@ export default function Home({ /> ))} - {/* - {bestSelling.slice(3, 6).map(({ node }) => ( + + {products.slice(0, 3).map((product, i) => ( - {featured.slice(3, 6).map(({ node }, i) => ( + {products.slice(0, 3).map((product, i) => ( ))} - {bestSelling.slice(0, 3).map(({ node }) => ( + {products.slice(0, 3).map((product, i) => ( ))} - */} + {/*