mirror of
https://github.com/vercel/commerce.git
synced 2025-06-18 05:01:22 +00:00
Add a filter to avoid duplicated items at same section
This commit is contained in:
parent
bbcf63b892
commit
6df3a164d6
@ -49,13 +49,17 @@ export async function getStaticProps({
|
|||||||
// products, then fill them with products from the products list, this
|
// 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
|
// is useful for new commerce sites that don't have a lot of products
|
||||||
return {
|
return {
|
||||||
featured: rangeMap(6, (i) => featuredProducts[i] ?? products.shift())
|
featured: rangeMap(
|
||||||
|
6,
|
||||||
|
(i) => featuredProducts[i] ?? nonDuplicated(products, featuredProducts)
|
||||||
|
)
|
||||||
.filter(nonNullable)
|
.filter(nonNullable)
|
||||||
.sort((a, b) => a.node.prices.price.value - b.node.prices.price.value)
|
.sort((a, b) => a.node.prices.price.value - b.node.prices.price.value)
|
||||||
.reverse(),
|
.reverse(),
|
||||||
bestSelling: rangeMap(
|
bestSelling: rangeMap(
|
||||||
6,
|
6,
|
||||||
(i) => bestSellingProducts[i] ?? products.shift()
|
(i) =>
|
||||||
|
bestSellingProducts[i] ?? nonDuplicated(products, bestSellingProducts)
|
||||||
).filter(nonNullable),
|
).filter(nonNullable),
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
@ -75,6 +79,16 @@ export async function getStaticProps({
|
|||||||
|
|
||||||
const nonNullable = (v: any) => v
|
const nonNullable = (v: any) => v
|
||||||
|
|
||||||
|
const nonDuplicated: any = (products: any[], arr: any[]) => {
|
||||||
|
if (!!products.length) {
|
||||||
|
const product = products.shift()
|
||||||
|
return !arr.some(({ node }) => node.entityId === product.node.entityId)
|
||||||
|
? product
|
||||||
|
: nonDuplicated(products, arr)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
export default function Home({
|
export default function Home({
|
||||||
featured,
|
featured,
|
||||||
bestSelling,
|
bestSelling,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user