{
if ( ! siteSearchTerm ) {
return;
}
setSiteData( {
gridSkeleton: true,
} );
} }
onSearchResult={ ( response ) => {
if ( ! siteSearchTerm ) {
setSiteData( {
gridSkeleton: false,
} );
return;
}
const results = [];
if ( response.success ) {
if ( response.ids.length ) {
for ( const id of response.ids ) {
if ( allFilteredSites[ id ] ) {
const selectedTemplate =
allFilteredSites[ id ];
if (
selectedTemplate.related_ecommerce_template !==
undefined &&
selectedTemplate.related_ecommerce_template !==
'' &&
selectedTemplate.ecommerce_parent_template !==
undefined &&
selectedTemplate.ecommerce_parent_template !==
''
) {
// If ecommerce_parent_template is not empty, skip adding the site to allSites.
continue;
}
results[ id ] = allFilteredSites[ id ];
}
}
}
}
collectTerms( Object.keys( results ).length );
setSiteData( {
sites: results,
gridSkeleton: false,
} );
} }
value={ decodeEntities( siteSearchTerm ) }
placeholder={ __(
'Search for Starter Templates',
'astra-sites'
) }
onSearch={ ( event, newSearchTerm ) => {
const newSiteData = {
gridSkeleton: true,
};
if ( ! newSearchTerm ) {
newSiteData.sites = allFilteredSites;
}
setSiteData( newSiteData );
dispatch( {
type: 'set',
siteSearchTerm: newSearchTerm,
onMyFavorite: false,
siteBusinessType: '',
selectedMegaMenu: '',
siteType: '',
siteOrder: 'popular',
} );
const urlParam = setURLParmsValue( 's', newSearchTerm );
history( `?${ urlParam }` );
} }
onKeyUp={ onSearchKeyUp }
/>
);
};
export default SiteSearch;