woocommerce/plugins/woocommerce-admin/client/marketplace/components/extensions/extensions.tsx

60 lines
1.5 KiB
TypeScript
Raw Normal View History

/**
* External dependencies
*/
2023-08-09 13:04:35 +00:00
import { useContext } from '@wordpress/element';
2023-08-15 12:37:50 +00:00
import { __, _n, sprintf } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import './extensions.scss';
import CategorySelector from '../category-selector/category-selector';
2023-08-10 07:16:56 +00:00
import { ProductListContext } from '../../contexts/product-list-context';
import ProductListContent from '../product-list-content/product-list-content';
2023-08-09 13:04:35 +00:00
import ProductLoader from '../product-loader/product-loader';
2023-08-15 12:37:50 +00:00
import NoResults from '../product-list-content/no-results';
export default function Extensions(): JSX.Element {
2023-08-10 07:16:56 +00:00
const productListContextValue = useContext( ProductListContext );
2023-08-09 13:04:35 +00:00
const { productList, isLoading } = productListContextValue;
const products = productList.slice( 0, 60 );
2023-08-15 12:37:50 +00:00
let title = __( '0 extensions found', 'woocommerce' );
2023-08-09 13:04:35 +00:00
if ( products.length > 0 ) {
title = sprintf(
// translators: %s: number of extensions
2023-08-15 12:37:50 +00:00
_n(
'%s extension',
'%s extensions',
products.length,
'woocommerce'
),
2023-08-09 13:04:35 +00:00
products.length
);
}
2023-08-10 07:16:56 +00:00
2023-08-15 12:37:50 +00:00
function content() {
if ( isLoading ) {
return <ProductLoader />;
}
if ( products.length === 0 ) {
return <NoResults />;
}
return <ProductListContent products={ products } />;
}
return (
<div className="woocommerce-marketplace__extensions">
2023-08-09 13:04:35 +00:00
<h2 className="woocommerce-marketplace__product-list-title woocommerce-marketplace__product-list-title--extensions">
{ title }
</h2>
<CategorySelector />
2023-08-15 12:37:50 +00:00
{ content() }
</div>
);
}