diff --git a/components/product/ProductCard/FUTURE_ProductCard.tsx b/components/product/ProductCard/FUTURE_ProductCard.tsx index 0b5c3aece..7ef41b0be 100644 --- a/components/product/ProductCard/FUTURE_ProductCard.tsx +++ b/components/product/ProductCard/FUTURE_ProductCard.tsx @@ -1,20 +1,18 @@ import { FC } from 'react' import cn from 'classnames' -import Image from 'next/image' +import Image, { ImageProps } from 'next/image' import s from './ProductCard.module.css' +// Restore Wishlist func // import WishlistButton from '@components/wishlist/WishlistButton' interface Props { className?: string product: Product variant?: 'slim' | 'simple' + imgProps?: Omit } -const ProductCard: FC = ({ className, product, variant }) => { - const defaultImageProps = { - layout: 'responsive', - } - +const ProductCard: FC = ({ className, product, variant, imgProps }) => { return ( {variant === 'slim' ? ( @@ -38,14 +36,13 @@ const ProductCard: FC = ({ className, product, variant }) => {
- {/* Image */} - {product.name}
diff --git a/framework/types.d.ts b/framework/types.d.ts index 40d7390a7..a05f03a69 100644 --- a/framework/types.d.ts +++ b/framework/types.d.ts @@ -13,13 +13,13 @@ interface Images { alt?: string } -interface NextImage { - src: string - width: number | string - height: number | string - layout?: 'fixed' | 'intrinsic' | 'responsive' | undefined - priority?: boolean - loading?: 'eager' | 'lazy' - sizes?: string - alt?: 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 copy.tsx b/pages/index copy.tsx new file mode 100644 index 000000000..ef1c0a96e --- /dev/null +++ b/pages/index copy.tsx @@ -0,0 +1,152 @@ +import rangeMap from '@lib/range-map' +import { Layout } from '@components/common' +import { ProductCard } from '@components/product' +import { Grid, Marquee, Hero } from '@components/ui' +import HomeAllProductsGrid from '@components/common/HomeAllProductsGrid' +import type { GetStaticPropsContext, InferGetStaticPropsType } from 'next' + +import { getConfig } from '@framework/api' +import getAllProducts from '@framework/api/operations/get-all-products' +import getSiteInfo from '@framework/api/operations/get-site-info' +import getAllPages from '@framework/api/operations/get-all-pages' + +export async function getStaticProps({ + preview, + locale, +}: GetStaticPropsContext) { + const config = getConfig({ locale }) + + // Get Featured Products + const { products: featuredProducts } = await getAllProducts({ + variables: { field: 'featuredProducts', first: 6 }, + config, + preview, + }) + + // Get Best Selling Products + const { products: bestSellingProducts } = await getAllProducts({ + variables: { field: 'bestSellingProducts', first: 6 }, + config, + preview, + }) + + // Get Best Newest Products + const { products: newestProducts } = await getAllProducts({ + variables: { field: 'newestProducts', first: 12 }, + config, + preview, + }) + + const { categories, brands } = await getSiteInfo({ config, preview }) + const { pages } = await getAllPages({ config, preview }) + + // These are the products that are going to be displayed in the landing. + // We prefer to do the computation at buildtime/servertime + const { featured, bestSelling } = (() => { + // Create a copy of products that we can mutate + const products = [...newestProducts] + // If the lists of featured and best selling products don't have enough + // products, then fill them with products from the products list, this + // is useful for new commerce sites that don't have a lot of products + return { + featured: rangeMap(6, (i) => featuredProducts[i] ?? products.shift()) + .filter(nonNullable) + .sort((a, b) => a.node.prices.price.value - b.node.prices.price.value) + .reverse(), + bestSelling: rangeMap( + 6, + (i) => bestSellingProducts[i] ?? products.shift() + ).filter(nonNullable), + } + })() + + return { + props: { + featured, + bestSelling, + newestProducts, + categories, + brands, + pages, + }, + revalidate: 14400, + } +} + +const nonNullable = (v: any) => v + +export default function Home({ + featured, + bestSelling, + brands, + categories, + newestProducts, +}: InferGetStaticPropsType) { + return ( +
+ + {featured.slice(0, 3).map(({ node }, i) => ( + + ))} + + + {bestSelling.slice(3, 6).map(({ node }) => ( + + ))} + + + + {featured.slice(3, 6).map(({ node }, i) => ( + + ))} + + + {bestSelling.slice(0, 3).map(({ node }) => ( + + ))} + + +
+ ) +} + +Home.Layout = Layout diff --git a/pages/index.tsx b/pages/index.tsx index ef1c0a96e..3266bc053 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,6 +1,6 @@ import rangeMap from '@lib/range-map' import { Layout } from '@components/common' -import { ProductCard } from '@components/product' +import ProductCard from '@components/product/ProductCard/FUTURE_ProductCard' import { Grid, Marquee, Hero } from '@components/ui' import HomeAllProductsGrid from '@components/common/HomeAllProductsGrid' import type { GetStaticPropsContext, InferGetStaticPropsType } from 'next' @@ -89,10 +89,10 @@ export default function Home({ ))} @@ -102,9 +102,10 @@ export default function Home({ key={node.path} product={node} variant="slim" - imgWidth={320} - imgHeight={320} - imgLayout="fixed" + imgProps={{ + width: 320, + height: 320, + }} /> ))} @@ -123,8 +124,10 @@ export default function Home({ ))} @@ -134,16 +137,17 @@ export default function Home({ key={node.path} product={node} variant="slim" - imgWidth={320} - imgHeight={320} - imgLayout="fixed" + imgProps={{ + width: 320, + height: 320, + }} /> ))} )