2023-07-20 13:53:06 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2023-08-08 14:29:08 +00:00
|
|
|
import { useEffect, useState } from '@wordpress/element';
|
2023-07-20 13:53:06 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2023-08-08 14:29:08 +00:00
|
|
|
import ProductList from '../product-list/product-list';
|
|
|
|
import { fetchDiscoverPageData, ProductGroup } from '../../utils/functions';
|
2023-07-04 12:08:50 +00:00
|
|
|
import './discover.scss';
|
2023-07-20 13:53:06 +00:00
|
|
|
|
2023-08-08 14:29:08 +00:00
|
|
|
export default function Discover(): JSX.Element | null {
|
|
|
|
const [ productGroups, setProductGroups ] = useState<
|
|
|
|
Array< ProductGroup >
|
|
|
|
>( [] );
|
|
|
|
|
|
|
|
useEffect( () => {
|
|
|
|
fetchDiscoverPageData().then( ( products: Array< ProductGroup > ) => {
|
|
|
|
setProductGroups( products );
|
|
|
|
} );
|
|
|
|
}, [] );
|
|
|
|
|
|
|
|
if ( ! productGroups.length ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
const groupsList = productGroups.flatMap( ( group ) => group );
|
2023-07-20 13:53:06 +00:00
|
|
|
return (
|
2023-07-04 12:08:50 +00:00
|
|
|
<div className="woocommerce-marketplace__discover">
|
2023-08-08 14:29:08 +00:00
|
|
|
{ groupsList.map( ( groups ) => (
|
|
|
|
<ProductList
|
|
|
|
key={ groups.id }
|
|
|
|
title={ groups.title }
|
|
|
|
products={ groups.items }
|
|
|
|
groupURL={ groups.url }
|
|
|
|
/>
|
|
|
|
) ) }
|
2023-07-20 13:53:06 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|