diff --git a/components/marketplace/index.js b/components/marketplace/index.js index 81f448e..38eee00 100644 --- a/components/marketplace/index.js +++ b/components/marketplace/index.js @@ -80,6 +80,7 @@ import { default as MarketplaceIsLoading } from '../marketplaceIsLoading/'; } } setIsLoading( false ); + applyStyles(); } }, [ marketplaceCategories ] ); @@ -97,6 +98,7 @@ import { default as MarketplaceIsLoading } from '../marketplaceIsLoading/'; let thecategories = []; categories.forEach((cat)=>{ cat.currentCount = constants.perPage; + cat.className = 'newfold-marketplace-tab-'+cat.name; if ( cat.products_count > 0 ) { thecategories.push(cat); @@ -114,7 +116,7 @@ import { default as MarketplaceIsLoading } from '../marketplaceIsLoading/'; const saveCategoryDisplayCount = (categoryName, newCount) => { let updatedMarketplaceCategories = [...marketplaceCategories]; // find matching cat, and update perPage amount - updatedMarketplaceCategories.forEach((cat)=>{ + updatedMarketplaceCategories.forEach( (cat) => { if (cat.name === categoryName ) { cat.currentCount = newCount; } @@ -122,6 +124,25 @@ import { default as MarketplaceIsLoading } from '../marketplaceIsLoading/'; setMarketplaceCategories( updatedMarketplaceCategories ); }; + /** + * Apply styles if they exist + */ + const applyStyles = () => { + if ( marketplaceCategories ) { + marketplaceCategories.forEach( (category) => { + if( + category.styles && // category has styles + !document.querySelector('[data-styleid="' + category.className + '"]') // not already added + ) { + const style = document.createElement("style") + style.textContent = category.styles; + style.dataset.styleid = category.className; + document.head.appendChild(style); + } + }); + } + }; + /** * render marketplace preloader * @@ -145,14 +166,14 @@ import { default as MarketplaceIsLoading } from '../marketplaceIsLoading/'; { ( tab ) => { return items.filter((item) => { - return item.categories.includes( category ); + return item.categories.includes( category.title ); }); }; @@ -65,11 +65,11 @@ const MarketplaceList = ({ marketplaceItems, currentCount, category, Components, * this is so users don't need to load more every time they click back into a category */ methods.useEffect(() => { - saveCategoryDisplayCount( category, itemsCount ); + saveCategoryDisplayCount( category.name, itemsCount ); }, [ itemsCount ] ); return ( -
+
{ activeItems.length > 0 && activeItems.map((item) => (