Skip to content

Commit 67aebd2

Browse files
feat: add minimum sites listing for onboarding template search
1 parent a5bf757 commit 67aebd2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

onboarding/src/Components/Sites.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import StarterSiteCard from './StarterSiteCard';
55
import VizSensor from 'react-visibility-sensor';
66
import Fuse from 'fuse.js/dist/fuse.min';
77

8+
const MINIMUM_SITES_LISTING = 10;
9+
810
const Sites = ( { getSites, editor, category, searchQuery } ) => {
911
const [ maxShown, setMaxShown ] = useState( 9 );
1012
const { sites = {} } = getSites;
@@ -14,10 +16,28 @@ const Sites = ( { getSites, editor, category, searchQuery } ) => {
1416
if ( Object.keys( allSites ).length === 0 ) {
1517
return [];
1618
}
19+
20+
/** @type {Array} */
1721
let builderSites = allSites[ editor ];
1822
builderSites = filterBySearch( builderSites );
1923
builderSites = filterByCategory( builderSites, category );
2024

25+
if ( MINIMUM_SITES_LISTING > builderSites.length ) {
26+
// Populate with the top searches if the number of eligible websites is lower than the minimum.
27+
for (const site of allSites[editor]) {
28+
if (builderSites.length >= MINIMUM_SITES_LISTING) {
29+
break;
30+
}
31+
if (builderSites.find(existing => existing.slug === site.slug)) {
32+
continue;
33+
}
34+
if (site?.upsell && 'free' === category ) { // For the `Free` category, all suggestion must be also free to keep consistency.
35+
continue;
36+
}
37+
builderSites.push(site);
38+
}
39+
}
40+
2141
return builderSites;
2242
};
2343

0 commit comments

Comments
 (0)