2023-10-06 08:17:56 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { useQuery } from '@woocommerce/navigation';
|
|
|
|
|
2023-10-04 16:59:34 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import './search-results.scss';
|
2023-10-06 08:17:56 +00:00
|
|
|
import { Product, ProductType, SearchResultType } from '../product-list/types';
|
|
|
|
import Products from '../products/products';
|
2023-10-04 16:59:34 +00:00
|
|
|
|
|
|
|
export interface SearchResultProps {
|
|
|
|
products: Product[];
|
2023-10-06 08:17:56 +00:00
|
|
|
type: SearchResultType;
|
2023-10-04 16:59:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default function SearchResults( props: SearchResultProps ): JSX.Element {
|
|
|
|
const extensions = props.products.filter(
|
|
|
|
( product ) => product.type === ProductType.extension
|
|
|
|
);
|
|
|
|
const themes = props.products.filter(
|
|
|
|
( product ) => product.type === ProductType.theme
|
|
|
|
);
|
|
|
|
|
2023-10-06 08:17:56 +00:00
|
|
|
const query = useQuery();
|
|
|
|
const showCategorySelector = query.section ? true : false;
|
|
|
|
|
2023-10-04 16:59:34 +00:00
|
|
|
return (
|
|
|
|
<div className="woocommerce-marketplace__search-results">
|
2023-10-06 08:17:56 +00:00
|
|
|
{ query?.section !== SearchResultType.theme && (
|
|
|
|
<Products
|
|
|
|
products={ extensions }
|
|
|
|
type={ ProductType.extension }
|
|
|
|
categorySelector={ showCategorySelector }
|
|
|
|
/>
|
|
|
|
) }
|
|
|
|
{ query?.section !== SearchResultType.extension && (
|
|
|
|
<Products
|
|
|
|
products={ themes }
|
|
|
|
type={ ProductType.theme }
|
|
|
|
categorySelector={ showCategorySelector }
|
|
|
|
/>
|
|
|
|
) }
|
2023-10-04 16:59:34 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|