2020-10-19 13:49:02 -05:00
|
|
|
|
import rangeMap from '@lib/range-map'
|
2020-11-04 11:50:23 -03:00
|
|
|
|
import { Layout } from '@components/common'
|
2020-10-04 16:34:22 -03:00
|
|
|
|
import { ProductCard } from '@components/product'
|
2020-11-06 16:30:08 -03:00
|
|
|
|
import { Grid, Marquee, Hero } from '@components/ui'
|
2020-11-04 11:50:23 -03:00
|
|
|
|
import HomeAllProductsGrid from '@components/common/HomeAllProductsGrid'
|
2020-11-06 16:30:08 -03:00
|
|
|
|
import type { GetStaticPropsContext, InferGetStaticPropsType } from 'next'
|
2020-09-30 13:36:02 -05:00
|
|
|
|
|
2020-10-29 12:10:53 -03:00
|
|
|
|
import { getConfig } from '@bigcommerce/storefront-data-hooks/api'
|
|
|
|
|
import getAllProducts from '@bigcommerce/storefront-data-hooks/api/operations/get-all-products'
|
|
|
|
|
import getSiteInfo from '@bigcommerce/storefront-data-hooks/api/operations/get-site-info'
|
|
|
|
|
import getAllPages from '@bigcommerce/storefront-data-hooks/api/operations/get-all-pages'
|
|
|
|
|
|
2020-10-24 16:10:31 -05:00
|
|
|
|
export async function getStaticProps({
|
|
|
|
|
preview,
|
|
|
|
|
locale,
|
|
|
|
|
}: GetStaticPropsContext) {
|
2020-10-25 15:14:54 -05:00
|
|
|
|
const config = getConfig({ locale })
|
2020-10-24 16:10:31 -05:00
|
|
|
|
|
2020-11-06 11:43:11 -03:00
|
|
|
|
// Get Featured Products
|
2020-10-19 11:47:39 -05:00
|
|
|
|
const { products: featuredProducts } = await getAllProducts({
|
2020-10-19 13:49:02 -05:00
|
|
|
|
variables: { field: 'featuredProducts', first: 6 },
|
2020-10-25 15:14:54 -05:00
|
|
|
|
config,
|
2020-10-27 00:47:29 -05:00
|
|
|
|
preview,
|
2020-10-19 13:49:02 -05:00
|
|
|
|
})
|
2020-11-06 11:43:11 -03:00
|
|
|
|
|
|
|
|
|
// Get Best Selling Products
|
2020-10-19 13:49:02 -05:00
|
|
|
|
const { products: bestSellingProducts } = await getAllProducts({
|
|
|
|
|
variables: { field: 'bestSellingProducts', first: 6 },
|
2020-10-25 15:14:54 -05:00
|
|
|
|
config,
|
2020-10-27 00:47:29 -05:00
|
|
|
|
preview,
|
2020-10-19 13:49:02 -05:00
|
|
|
|
})
|
2020-11-06 11:43:11 -03:00
|
|
|
|
|
|
|
|
|
// Get Best Newest Products
|
2020-10-19 13:49:02 -05:00
|
|
|
|
const { products: newestProducts } = await getAllProducts({
|
|
|
|
|
variables: { field: 'newestProducts', first: 12 },
|
2020-10-25 15:14:54 -05:00
|
|
|
|
config,
|
2020-10-27 00:47:29 -05:00
|
|
|
|
preview,
|
2020-10-19 11:47:39 -05:00
|
|
|
|
})
|
2020-11-06 11:43:11 -03:00
|
|
|
|
|
2020-10-27 00:47:29 -05:00
|
|
|
|
const { categories, brands } = await getSiteInfo({ config, preview })
|
|
|
|
|
const { pages } = await getAllPages({ config, preview })
|
2020-10-05 11:44:14 -03:00
|
|
|
|
|
2020-11-06 11:43:11 -03:00
|
|
|
|
// 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 } = (() => {
|
2020-10-19 13:49:02 -05:00
|
|
|
|
// 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 {
|
2020-10-26 21:06:36 -03:00
|
|
|
|
featured: rangeMap(6, (i) => featuredProducts[i] ?? products.shift())
|
|
|
|
|
.filter(nonNullable)
|
|
|
|
|
.sort((a, b) => a.node.prices.price.value - b.node.prices.price.value)
|
|
|
|
|
.reverse(),
|
2020-10-19 13:49:02 -05:00
|
|
|
|
bestSelling: rangeMap(
|
|
|
|
|
6,
|
|
|
|
|
(i) => bestSellingProducts[i] ?? products.shift()
|
|
|
|
|
).filter(nonNullable),
|
|
|
|
|
}
|
2020-11-06 11:43:11 -03:00
|
|
|
|
})()
|
2020-10-19 13:49:02 -05:00
|
|
|
|
|
2020-11-06 11:43:11 -03:00
|
|
|
|
return {
|
|
|
|
|
props: {
|
|
|
|
|
featured,
|
|
|
|
|
bestSelling,
|
|
|
|
|
newestProducts,
|
|
|
|
|
categories,
|
|
|
|
|
brands,
|
|
|
|
|
pages,
|
|
|
|
|
},
|
2020-11-07 19:15:54 -03:00
|
|
|
|
revalidate: 14400,
|
2020-11-06 11:43:11 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const nonNullable = (v: any) => v
|
|
|
|
|
|
|
|
|
|
export default function Home({
|
|
|
|
|
featured,
|
|
|
|
|
bestSelling,
|
|
|
|
|
brands,
|
|
|
|
|
categories,
|
|
|
|
|
newestProducts,
|
|
|
|
|
}: InferGetStaticPropsType<typeof getStaticProps>) {
|
2020-10-03 11:33:31 -03:00
|
|
|
|
return (
|
2020-10-21 19:22:27 -03:00
|
|
|
|
<div>
|
2020-10-16 12:46:02 -03:00
|
|
|
|
<Grid>
|
2020-10-21 21:28:28 -05:00
|
|
|
|
{featured.slice(0, 3).map(({ node }, i) => (
|
|
|
|
|
<ProductCard
|
|
|
|
|
key={node.path}
|
|
|
|
|
product={node}
|
2020-11-06 15:42:01 -03:00
|
|
|
|
imgWidth={i === 0 ? 1080 : 540}
|
|
|
|
|
imgHeight={i === 0 ? 1080 : 540}
|
2020-11-06 16:30:08 -03:00
|
|
|
|
imgPriority
|
|
|
|
|
imgLoading="eager"
|
2020-10-21 21:28:28 -05:00
|
|
|
|
/>
|
2020-10-16 12:46:02 -03:00
|
|
|
|
))}
|
|
|
|
|
</Grid>
|
2020-11-06 14:58:49 -03:00
|
|
|
|
<Marquee variant="secondary">
|
2020-10-26 21:06:36 -03:00
|
|
|
|
{bestSelling.slice(3, 6).map(({ node }) => (
|
2020-10-21 21:28:28 -05:00
|
|
|
|
<ProductCard
|
|
|
|
|
key={node.path}
|
|
|
|
|
product={node}
|
|
|
|
|
variant="slim"
|
|
|
|
|
imgWidth={320}
|
|
|
|
|
imgHeight={320}
|
2020-11-05 18:59:22 -03:00
|
|
|
|
imgLayout="fixed"
|
2020-10-21 21:28:28 -05:00
|
|
|
|
/>
|
2020-10-16 12:46:02 -03:00
|
|
|
|
))}
|
|
|
|
|
</Marquee>
|
2020-10-04 17:47:05 -03:00
|
|
|
|
<Hero
|
|
|
|
|
headline="Release Details: The Yeezy BOOST 350 V2 ‘Natural'"
|
|
|
|
|
description="
|
|
|
|
|
The Yeezy BOOST 350 V2 lineup continues to grow. We recently had the
|
|
|
|
|
‘Carbon’ iteration, and now release details have been locked in for
|
|
|
|
|
this ‘Natural’ joint. Revealed by Yeezy Mafia earlier this year, the
|
|
|
|
|
shoe was originally called ‘Abez’, which translated to ‘Tin’ in
|
|
|
|
|
Hebrew. It’s now undergone a name change, and will be referred to as
|
|
|
|
|
‘Natural’."
|
|
|
|
|
/>
|
2020-10-16 12:46:02 -03:00
|
|
|
|
<Grid layout="B">
|
2020-10-21 21:28:28 -05:00
|
|
|
|
{featured.slice(3, 6).map(({ node }, i) => (
|
|
|
|
|
<ProductCard
|
|
|
|
|
key={node.path}
|
|
|
|
|
product={node}
|
2020-11-06 15:42:01 -03:00
|
|
|
|
imgWidth={i === 1 ? 1080 : 540}
|
|
|
|
|
imgHeight={i === 1 ? 1080 : 540}
|
2020-10-21 21:28:28 -05:00
|
|
|
|
/>
|
2020-10-16 12:46:02 -03:00
|
|
|
|
))}
|
|
|
|
|
</Grid>
|
|
|
|
|
<Marquee>
|
2020-10-26 21:06:36 -03:00
|
|
|
|
{bestSelling.slice(0, 3).map(({ node }) => (
|
2020-10-21 21:28:28 -05:00
|
|
|
|
<ProductCard
|
|
|
|
|
key={node.path}
|
|
|
|
|
product={node}
|
|
|
|
|
variant="slim"
|
|
|
|
|
imgWidth={320}
|
|
|
|
|
imgHeight={320}
|
2020-11-05 18:59:22 -03:00
|
|
|
|
imgLayout="fixed"
|
2020-10-21 21:28:28 -05:00
|
|
|
|
/>
|
2020-10-16 12:46:02 -03:00
|
|
|
|
))}
|
|
|
|
|
</Marquee>
|
2020-10-26 20:02:29 -03:00
|
|
|
|
<HomeAllProductsGrid
|
|
|
|
|
categories={categories}
|
|
|
|
|
brands={brands}
|
|
|
|
|
newestProducts={newestProducts}
|
2020-11-06 14:58:49 -03:00
|
|
|
|
/>
|
2020-10-12 10:46:17 -03:00
|
|
|
|
</div>
|
2020-10-03 11:33:31 -03:00
|
|
|
|
)
|
2020-09-30 11:44:38 -05:00
|
|
|
|
}
|
2020-10-01 21:30:08 -05:00
|
|
|
|
|
|
|
|
|
Home.Layout = Layout
|