import { RecommendationsGrid } from '@recommendations/components/RecommendationsGrid'; import { selectIsError, selectIsLoading, selectRecommendations, } from '@recommendations/selectors/plugin-search'; import { usePluginSearchStore } from '@recommendations/state/plugin-search'; import { recordActivity } from '@recommendations/utils/record-activity'; import { useEffect } from '@wordpress/element'; import { __, sprintf } from '@wordpress/i18n'; import { safeDecodeURIComponent } from '@wordpress/url'; const showPartnerBranding = window.extRecommendationsData?.showPartnerBranding && window.extSharedData?.partnerLogo; export const PluginSearchBanner = () => { const query = usePluginSearchStore((state) => state.query); const isLoading = usePluginSearchStore(selectIsLoading); const isError = usePluginSearchStore(selectIsError); const recommendationsLimit = usePluginSearchStore( (state) => state.recommendationsLimit, ); const recommendations = usePluginSearchStore(selectRecommendations); const fetchInstalledPlugins = usePluginSearchStore( (state) => state.fetchInstalledPlugins, ); useEffect(() => { if (!query || isLoading) return; recordActivity({ slot: 'plugin-search', event: 'search' }); }, [query, isLoading]); useEffect(() => { if (!query) return; fetchInstalledPlugins(true); }, [query, fetchInstalledPlugins]); if (!query || !recommendations?.length || isLoading || isError) { return null; } return (
{showPartnerBranding ? ( <> {window.extSharedData?.partnerName
) : null}

{sprintf( // translators: %s: The search query term __('Recommended Solutions for: %s', 'extendify-local'), safeDecodeURIComponent(query), )}

); };