2020-10-19 13:49:02 -05:00
|
|
|
|
import { useMemo } from 'react'
|
2020-10-01 20:40:40 -05:00
|
|
|
|
import { GetStaticPropsContext, InferGetStaticPropsType } from 'next'
|
2020-10-02 14:51:36 -03:00
|
|
|
|
import getAllProducts from '@lib/bigcommerce/api/operations/get-all-products'
|
2020-10-19 13:49:02 -05:00
|
|
|
|
import getSiteInfo from '@lib/bigcommerce/api/operations/get-site-info'
|
|
|
|
|
import getAllPages from '@lib/bigcommerce/api/operations/get-all-pages'
|
|
|
|
|
import rangeMap from '@lib/range-map'
|
2020-10-01 20:40:40 -05:00
|
|
|
|
import { Layout } from '@components/core'
|
2020-10-04 16:34:22 -03:00
|
|
|
|
import { Grid, Marquee, Hero } from '@components/ui'
|
|
|
|
|
import { ProductCard } from '@components/product'
|
2020-09-30 13:36:02 -05:00
|
|
|
|
|
|
|
|
|
export async function getStaticProps({ preview }: GetStaticPropsContext) {
|
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 },
|
|
|
|
|
})
|
|
|
|
|
const { products: bestSellingProducts } = await getAllProducts({
|
|
|
|
|
variables: { field: 'bestSellingProducts', first: 6 },
|
|
|
|
|
})
|
|
|
|
|
const { products: newestProducts } = await getAllProducts({
|
|
|
|
|
variables: { field: 'newestProducts', first: 12 },
|
2020-10-19 11:47:39 -05:00
|
|
|
|
})
|
2020-10-10 14:19:05 -05:00
|
|
|
|
const { categories, brands } = await getSiteInfo()
|
2020-10-19 13:49:02 -05:00
|
|
|
|
const { pages } = await getAllPages()
|
2020-10-05 11:44:14 -03:00
|
|
|
|
|
2020-09-30 13:36:02 -05:00
|
|
|
|
return {
|
2020-10-19 13:49:02 -05:00
|
|
|
|
props: {
|
|
|
|
|
featuredProducts,
|
|
|
|
|
bestSellingProducts,
|
|
|
|
|
newestProducts,
|
|
|
|
|
categories,
|
|
|
|
|
brands,
|
|
|
|
|
pages,
|
|
|
|
|
},
|
|
|
|
|
revalidate: 10,
|
2020-10-01 20:40:40 -05:00
|
|
|
|
}
|
2020-09-30 13:36:02 -05:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-19 13:49:02 -05:00
|
|
|
|
const nonNullable = (v: any) => v
|
|
|
|
|
|
2020-09-30 13:36:02 -05:00
|
|
|
|
export default function Home({
|
2020-10-19 11:47:39 -05:00
|
|
|
|
featuredProducts,
|
2020-10-19 13:49:02 -05:00
|
|
|
|
bestSellingProducts,
|
|
|
|
|
newestProducts,
|
2020-10-08 18:48:28 -05:00
|
|
|
|
categories,
|
2020-10-10 14:19:05 -05:00
|
|
|
|
brands,
|
2020-09-30 13:36:02 -05:00
|
|
|
|
}: InferGetStaticPropsType<typeof getStaticProps>) {
|
2020-10-19 13:49:02 -05:00
|
|
|
|
const { featured, bestSelling } = useMemo(() => {
|
|
|
|
|
// 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),
|
|
|
|
|
bestSelling: rangeMap(
|
|
|
|
|
6,
|
|
|
|
|
(i) => bestSellingProducts[i] ?? products.shift()
|
|
|
|
|
).filter(nonNullable),
|
|
|
|
|
}
|
|
|
|
|
// Props from getStaticProps won't change
|
|
|
|
|
}, [])
|
|
|
|
|
|
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-19 13:49:02 -05:00
|
|
|
|
{featured.slice(0, 3).map(({ node }) => (
|
2020-10-19 12:40:26 -05:00
|
|
|
|
<ProductCard key={node.path} product={node} />
|
2020-10-16 12:46:02 -03:00
|
|
|
|
))}
|
|
|
|
|
</Grid>
|
|
|
|
|
<Marquee variant="secondary">
|
2020-10-22 18:24:04 -03:00
|
|
|
|
{bestSelling.slice(3, 6).map(({ node }) => (
|
2020-10-19 12:40:26 -05:00
|
|
|
|
<ProductCard key={node.path} product={node} variant="slim" />
|
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-19 13:49:02 -05:00
|
|
|
|
{featured.slice(3, 6).map(({ node }) => (
|
2020-10-19 12:40:26 -05:00
|
|
|
|
<ProductCard key={node.path} product={node} />
|
2020-10-16 12:46:02 -03:00
|
|
|
|
))}
|
|
|
|
|
</Grid>
|
|
|
|
|
<Marquee>
|
2020-10-19 13:49:02 -05:00
|
|
|
|
{bestSelling.slice(3, 6).map(({ node }) => (
|
2020-10-19 12:40:26 -05:00
|
|
|
|
<ProductCard key={node.path} product={node} variant="slim" />
|
2020-10-16 12:46:02 -03:00
|
|
|
|
))}
|
|
|
|
|
</Marquee>
|
2020-10-13 08:53:05 -03:00
|
|
|
|
<div className="py-12 flex flex-row w-full px-12">
|
2020-10-17 23:00:09 -03:00
|
|
|
|
<div className="pr-3 w-48 relative">
|
2020-10-21 19:22:27 -03:00
|
|
|
|
<div className="sticky top-32">
|
2020-10-17 23:00:09 -03:00
|
|
|
|
<ul className="mb-10">
|
|
|
|
|
<li className="py-1 text-base font-bold tracking-wide">
|
|
|
|
|
All Categories
|
2020-10-08 18:48:28 -05:00
|
|
|
|
</li>
|
2020-10-17 23:00:09 -03:00
|
|
|
|
{categories.map((cat) => (
|
|
|
|
|
<li key={cat.path} className="py-1 text-accents-8">
|
|
|
|
|
<a href="#">{cat.name}</a>
|
|
|
|
|
</li>
|
|
|
|
|
))}
|
|
|
|
|
</ul>
|
|
|
|
|
<ul className="">
|
|
|
|
|
<li className="py-1 text-base font-bold tracking-wide">
|
|
|
|
|
All Designers
|
2020-10-10 14:19:05 -05:00
|
|
|
|
</li>
|
2020-10-17 23:00:09 -03:00
|
|
|
|
{brands.flatMap(({ node }) => (
|
|
|
|
|
<li key={node.path} className="py-1 text-accents-8">
|
|
|
|
|
<a href="#">{node.name}</a>
|
|
|
|
|
</li>
|
|
|
|
|
))}
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
2020-10-05 11:44:14 -03:00
|
|
|
|
</div>
|
|
|
|
|
<div className="flex-1">
|
2020-10-16 12:46:02 -03:00
|
|
|
|
<Grid layout="normal">
|
2020-10-19 13:49:02 -05:00
|
|
|
|
{newestProducts.map(({ node }) => (
|
2020-10-19 12:40:26 -05:00
|
|
|
|
<ProductCard key={node.path} product={node} variant="simple" />
|
2020-10-16 12:46:02 -03:00
|
|
|
|
))}
|
|
|
|
|
</Grid>
|
2020-10-04 16:34:22 -03:00
|
|
|
|
</div>
|
2020-10-04 15:16:56 -03:00
|
|
|
|
</div>
|
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
|