File size: 3,778 Bytes
1e92f2d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | import { useSelector } from 'react-redux';
import { isCompatiblePlugin } from 'calypso/my-sites/plugins/plugin-compatibility';
import { isUserLoggedIn } from 'calypso/state/current-user/selectors';
import { getSiteOption } from 'calypso/state/sites/selectors';
import { getSelectedSiteId } from 'calypso/state/ui/selectors';
import { WPBEGINNER_PLUGINS } from '../constants';
import EducationFooter from '../education-footer';
import CollectionListView from '../plugins-browser/collection-list-view';
import SingleListView, { SHORT_LIST_LENGTH } from '../plugins-browser/single-list-view';
import usePlugins from '../use-plugins';
import InPageCTASection from './in-page-cta-section';
import UpgradeNudge from './upgrade-nudge';
/**
* Module variables
*/
function filterPopularPlugins( popularPlugins = [], featuredPlugins = [] ) {
const displayedFeaturedSlugsMap = new Map(
featuredPlugins
.slice( 0, SHORT_LIST_LENGTH ) // only displayed plugins
.map( ( plugin ) => [ plugin.slug, plugin.slug ] )
);
return popularPlugins.filter(
( plugin ) =>
! displayedFeaturedSlugsMap.has( plugin.slug ) && isCompatiblePlugin( plugin.slug )
);
}
export const PaidPluginsSection = ( props ) => {
const { plugins: paidPlugins = [], isFetching: isFetchingPaidPlugins } = usePlugins( {
category: 'paid',
} );
if ( props.jetpackNonAtomic ) {
return null;
}
return (
<SingleListView
{ ...props }
category="paid"
plugins={ paidPlugins }
isFetching={ isFetchingPaidPlugins }
/>
);
};
export const FeaturePartnerBundlePlugins = ( props ) => {
const { category } = props;
const { plugins, isFetching } = usePlugins( {
category,
infinite: true,
slugs: WPBEGINNER_PLUGINS,
} );
return <SingleListView { ...props } plugins={ plugins } isFetching={ isFetching } />;
};
const FeaturedPluginsSection = ( props ) => {
return (
<SingleListView
{ ...props }
plugins={ props.pluginsByCategoryFeatured }
isFetching={ props.isFetchingPluginsByCategoryFeatured }
category="featured"
/>
);
};
const PopularPluginsSection = ( props ) => {
const { plugins: popularPlugins = [], isFetching: isFetchingPluginsByCategoryPopular } =
usePlugins( {
category: 'popular',
} );
const pluginsByCategoryPopular = filterPopularPlugins(
popularPlugins,
props.pluginsByCategoryFeatured
);
return (
<SingleListView
{ ...props }
category="popular"
plugins={ pluginsByCategoryPopular }
isFetching={ isFetchingPluginsByCategoryPopular }
/>
);
};
const PluginsDiscoveryPage = ( props ) => {
const {
plugins: pluginsByCategoryFeatured = [],
isFetching: isFetchingPluginsByCategoryFeatured,
} = usePlugins( {
category: 'featured',
} );
const isLoggedIn = useSelector( isUserLoggedIn );
const siteId = useSelector( getSelectedSiteId );
const sitePartnerBundle = useSelector( ( state ) =>
getSiteOption( state, siteId, 'site_partner_bundle' )
);
const isWPBeginnerSpecial = sitePartnerBundle === 'wpbeginner-special';
return (
<>
<UpgradeNudge { ...props } paidPlugins />
{ isWPBeginnerSpecial && <FeaturePartnerBundlePlugins { ...props } category="wpbeginner" /> }
<PaidPluginsSection { ...props } />
<CollectionListView category="monetization" { ...props } />
<EducationFooter />
{ ! isLoggedIn && <InPageCTASection /> }
<FeaturedPluginsSection
{ ...props }
pluginsByCategoryFeatured={ pluginsByCategoryFeatured }
isFetchingPluginsByCategoryFeatured={ isFetchingPluginsByCategoryFeatured }
/>
<CollectionListView category="business" { ...props } />
<PopularPluginsSection { ...props } pluginsByCategoryFeatured={ pluginsByCategoryFeatured } />
<CollectionListView category="ecommerce" { ...props } />
</>
);
};
export default PluginsDiscoveryPage;
|