mirror of
https://github.com/vercel/commerce.git
synced 2025-07-23 04:36:49 +00:00
♻️ enhan: not show fresh product item when empty
:%s
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
|
import { ProductCard } from '@commerce/types/product';
|
||||||
import { ProductVariables } from '@framework/api/operations/get-all-products';
|
import { ProductVariables } from '@framework/api/operations/get-all-products';
|
||||||
import { Product } from '@framework/schema';
|
|
||||||
import commerce from '@lib/api/commerce';
|
import commerce from '@lib/api/commerce';
|
||||||
import { GetStaticPropsContext } from 'next';
|
import { GetStaticPropsContext } from 'next';
|
||||||
import { Layout } from 'src/components/common';
|
import { Layout } from 'src/components/common';
|
||||||
@@ -8,8 +8,8 @@ import HomeSpice from 'src/components/modules/home/HomeSpice/HomeSpice';
|
|||||||
import { getAllFeaturedFacetId, getFreshProductFacetId } from 'src/utils/funtion.utils';
|
import { getAllFeaturedFacetId, getFreshProductFacetId } from 'src/utils/funtion.utils';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
freshProducts: Product[],
|
freshProducts: ProductCard[],
|
||||||
featuredProducts: Product[],
|
featuredProducts: ProductCard[],
|
||||||
|
|
||||||
}
|
}
|
||||||
export default function Home({ freshProducts, featuredProducts }: Props) {
|
export default function Home({ freshProducts, featuredProducts }: Props) {
|
||||||
@@ -74,7 +74,7 @@ export async function getStaticProps({
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
freshProducts: rs[0].products,
|
freshProducts: freshFacetId ? rs[0].products : [],
|
||||||
featuredProducts: rs[1].products
|
featuredProducts: rs[1].products
|
||||||
},
|
},
|
||||||
revalidate: 60,
|
revalidate: 60,
|
||||||
|
@@ -1,11 +1,15 @@
|
|||||||
|
import { ProductCard } from '@commerce/types/product'
|
||||||
import { Product } from '@framework/schema'
|
import { Product } from '@framework/schema'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import { CollectionCarcousel } from '..'
|
import { CollectionCarcousel } from '..'
|
||||||
interface FreshProductsProps {
|
interface FreshProductsProps {
|
||||||
data: Product[]
|
data: ProductCard[]
|
||||||
}
|
}
|
||||||
|
|
||||||
const FreshProducts = ({data}: FreshProductsProps) => {
|
const FreshProducts = ({ data }: FreshProductsProps) => {
|
||||||
|
if (data.length === 0) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<CollectionCarcousel
|
<CollectionCarcousel
|
||||||
|
@@ -95,14 +95,6 @@ const dataTest = [
|
|||||||
const HomeCollection = (props: HomeCollectionProps) => {
|
const HomeCollection = (props: HomeCollectionProps) => {
|
||||||
return (
|
return (
|
||||||
<div className="w-full">
|
<div className="w-full">
|
||||||
<CollectionCarcousel
|
|
||||||
type="highlight"
|
|
||||||
data={dataTest}
|
|
||||||
itemKey="product-1"
|
|
||||||
title="Fresh Products Today"
|
|
||||||
subtitle="Last call! Shop deep deals on 100+ bulk picks while you can."
|
|
||||||
category={"veggie"}
|
|
||||||
/>
|
|
||||||
<CollectionCarcousel
|
<CollectionCarcousel
|
||||||
data={dataTest}
|
data={dataTest}
|
||||||
itemKey="product-2"
|
itemKey="product-2"
|
||||||
|
Reference in New Issue
Block a user