File indexing completed on 2024-12-22 05:35:13
0001 import React, { useState } from 'react'; 0002 import ReactDOM from 'react-dom'; 0003 import { 0004 ConvertObjectToArray, 0005 GetSelectedCategory, 0006 GenerateCurrentViewedCategories, 0007 GetCategoriesBySearchPhrase, 0008 sortArrayAlphabeticallyByTitle, 0009 getUrlContext 0010 } from './category-helpers'; 0011 0012 let isShowRealDomainAsUrl = 1, showStoreListingsFirst = false; 0013 if (window.is_show_real_domain_as_url === 1) isShowRealDomainAsUrl = 1; 0014 else { 0015 if (window.config.sName === "www.pling.cc" || window.config.sName === "www.pling.com"){ isShowRealDomainAsUrl = 1; } 0016 if (window.location.href === "https://www.pling.cc" || window.location.href === "https://www.pling.com" || window.location.href === "http://192.168.2.124" || 0017 window.location.href === "https://www.pling.cc/" || window.location.href === "https://www.pling.com/" || window.location.href === "http://192.168.2.124/"){ 0018 showStoreListingsFirst = true; 0019 } 0020 } 0021 0022 function CategoryTree(){ 0023 0024 /* STATE */ 0025 0026 let initialCatTree = [...window.catTree] 0027 0028 const [ categoryTree, setCategoryTree ] = useState(initialCatTree); 0029 const [ categoryId, SetCategoryId ] = useState(window.categoryId); 0030 const [ cat_tree_filter, setCat_tree_filter ] = useState(window.cat_tree_filter); 0031 0032 const [ selectedCategory, setSelectedCategory ] = useState(GetSelectedCategory(categoryTree,categoryId)); 0033 0034 let initialCurrentViewedCategories = [] 0035 if (selectedCategory){ 0036 initialCurrentViewedCategories = GenerateCurrentViewedCategories(categoryTree,selectedCategory,[]) 0037 if (selectedCategory.has_children === true) initialCurrentViewedCategories.push(selectedCategory); 0038 if (initialCurrentViewedCategories.length > 0){ 0039 initialCurrentViewedCategories.forEach(function(icvc,index){ 0040 icvc.level = index + 1; 0041 }) 0042 } 0043 } 0044 0045 let initialSelectedCategoriesId = []; 0046 initialCurrentViewedCategories.forEach(function(c,index){ 0047 initialSelectedCategoriesId.push(c.id); 0048 }); 0049 0050 const [ selectedCategoriesId, setSelectedCategoriesId ] = useState(initialSelectedCategoriesId) 0051 const [ currentViewedCategories, setCurrentViewedCategories ] = useState(initialCurrentViewedCategories); 0052 0053 let initialCurrentCategoryLevel = initialCurrentViewedCategories.length; 0054 // if (isShowRealDomainAsUrl && showStoreListingsFirst) initialCurrentCategoryLevel = -1; 0055 const [ currentCategoryLevel, setCurrentCategoryLevel ] = useState(initialCurrentCategoryLevel); 0056 0057 const [ searchPhrase, setSearchPhrase ] = useState(); 0058 const [ searchMode, setSearchMode ] = useState(); 0059 0060 const [ showBackButton, setShowBackButton ] = useState(true); 0061 const [ showBreadCrumbs, setShowBreadCrumbs ] = useState(true); 0062 const [ showForwardButton, setShowForwardButton ] = useState(false); 0063 0064 let initialStoreInfo; 0065 if (window.config.sName){ 0066 json_store_for_tree.forEach(function(d,index){ 0067 if (d.host === window.config.sName){ 0068 initialStoreInfo = d; 0069 } 0070 }); 0071 } 0072 0073 const [ storeInfo, setStoreInfo ] = useState(initialStoreInfo); 0074 0075 /* COMPONENT */ 0076 0077 React.useEffect(() => { onSearchPhraseUpdate() },[searchPhrase]) 0078 0079 // on search phrase update 0080 function onSearchPhraseUpdate(){ 0081 let newSearchMode = false; 0082 if (searchPhrase){ 0083 let newCurrentViewedCategories; 0084 if (searchPhrase.length > 0){ 0085 newSearchMode = true; 0086 newCurrentViewedCategories = [...currentViewedCategories]; 0087 setCurrentViewedCategories(newCurrentViewedCategories); 0088 if (searchMode === true) newCurrentViewedCategories.length = selectedCategoriesId.length; 0089 let searchPhraseCategories = GetCategoriesBySearchPhrase(categoryTree,searchPhrase); 0090 newCurrentViewedCategories = [ 0091 ...newCurrentViewedCategories, 0092 {categoryId:"-1",id:"-1",title:'Search',searchPhrase:searchPhrase,categories:searchPhraseCategories} 0093 ] 0094 } else { 0095 newCurrentViewedCategories = [...currentViewedCategories]; 0096 newCurrentViewedCategories.length = selectedCategoriesId.length; 0097 } 0098 setCurrentViewedCategories(newCurrentViewedCategories); 0099 setCurrentCategoryLevel(newCurrentViewedCategories.length) 0100 } else if (searchMode === true){ 0101 let newCurrentViewedCategories = [...currentViewedCategories]; 0102 newCurrentViewedCategories.length = selectedCategoriesId.length; 0103 setCurrentViewedCategories(newCurrentViewedCategories); 0104 setCurrentCategoryLevel(newCurrentViewedCategories.length) 0105 } 0106 setSearchMode(newSearchMode); 0107 } 0108 0109 // on header navigation item click 0110 function onHeaderNavigationItemClick(cvc){ 0111 setCurrentCategoryLevel(cvc.level) 0112 const trimedCurrentViewedCategoriesArray = currentViewedCategories; 0113 trimedCurrentViewedCategoriesArray.length = cvc.level + 1; 0114 setCurrentViewedCategories(trimedCurrentViewedCategoriesArray) 0115 } 0116 0117 // go back 0118 function goBack(){ 0119 const newCurrentCategoryLevel = currentCategoryLevel - 1; 0120 setCurrentCategoryLevel(newCurrentCategoryLevel); 0121 const newSearchPhrase = ''; 0122 const newSearchMode = false; 0123 setSearchPhrase(newSearchPhrase); 0124 setSearchMode(newSearchMode); 0125 } 0126 0127 // go forward 0128 function goForward(){ 0129 const newCurrentCategoryLevel = currentCategoryLevel + 1; 0130 setCurrentCategoryLevel(newCurrentCategoryLevel); 0131 const newSearchPhrase = ''; 0132 const newSearchMode = false; 0133 setSearchPhrase(newSearchPhrase); 0134 setSearchMode(newSearchMode); 0135 } 0136 0137 // on category panel item click 0138 function onCategoryPanleItemClick(ccl,cvc){ 0139 const newCurrentCategoryLevel = ccl; 0140 const newCurrentViewedCategories = cvc; 0141 setCurrentCategoryLevel(newCurrentCategoryLevel) 0142 setCurrentViewedCategories(newCurrentViewedCategories) 0143 } 0144 0145 // search phrase 0146 function onSetSearchPhrase(e){ 0147 setSearchPhrase(e.target.value); 0148 } 0149 0150 /* RENDER */ 0151 0152 let tagCloudDisplay; 0153 if (selectedCategory) tagCloudDisplay = <CategoryTagCloud selectedCategory={selectedCategory} /> 0154 0155 let searchInputDisplay; 0156 searchInputDisplay = ( 0157 <input type="text" defaultValue={searchPhrase} onChange={e => onSetSearchPhrase(e)}/> 0158 ) 0159 0160 return( 0161 <div id="category-tree"> 0162 {searchInputDisplay} 0163 <CategoryTreeHeader 0164 currentCategoryLevel={currentCategoryLevel} 0165 currentViewedCategories={currentViewedCategories} 0166 showBackButton={showBackButton} 0167 showBreadCrumbs={showBreadCrumbs} 0168 showForwardButton={showForwardButton} 0169 storeInfo={storeInfo} 0170 onHeaderNavigationItemClick={(cvc) => onHeaderNavigationItemClick(cvc)} 0171 onGoBackClick={goBack} 0172 onGoForwardClick={goForward} 0173 cat_tree_filter={cat_tree_filter} 0174 /> 0175 <CategoryPanelsContainer 0176 categoryTree={categoryTree} 0177 categoryId={categoryId} 0178 searchPhrase={searchPhrase} 0179 searchMode={searchMode} 0180 currentCategoryLevel={currentCategoryLevel} 0181 currentViewedCategories={currentViewedCategories} 0182 selectedCategoriesId={selectedCategoriesId} 0183 storeInfo={storeInfo} 0184 onCategoryPanleItemClick={(ccl,cvc,catLink) => onCategoryPanleItemClick(ccl,cvc,catLink)} 0185 onSetShowBreadCrumbs={(val) => setShowBreadCrumbs(val)} 0186 onSetShowBackButton={(val) => setShowBackButton(val)} 0187 onSetShowForwardButton={(val) => setShowForwardButton(val)} 0188 cat_tree_filter={cat_tree_filter} 0189 /> 0190 {tagCloudDisplay} 0191 </div> 0192 ) 0193 } 0194 0195 function CategoryTreeHeader(props){ 0196 0197 const initialCurrentViewedCategories = props.currentViewedCategories.slice(0,props.currentCategoryLevel); 0198 const [ categories, setCategories ] = useState(initialCurrentViewedCategories) 0199 React.useEffect(() => { 0200 const newCurrentViewedCategories = props.currentViewedCategories.slice(0,props.currentCategoryLevel); 0201 setCategories(newCurrentViewedCategories); 0202 },[props.currentViewedCategories,props.currentCategoryLevel]) 0203 0204 function onHeaderNavigationItemClick(cvc,index){ 0205 props.onHeaderNavigationItemClick(cvc); 0206 const newCategories = categories; 0207 newCategories.length = index + 1; 0208 setCategories(newCategories) 0209 } 0210 0211 let categoryTreeHeaderNavigationDisplay; 0212 if (categories.length > 0){ 0213 categoryTreeHeaderNavigationDisplay = categories.map((cvc,index) =>{ 0214 if (categories.length === index + 1){ 0215 let catLink; 0216 if (cvc.title !== "Search") catLink = getUrlContext(window.location.href) + ( cvc.id === "00" ? "/browse/" : "/browse/cat/"+cvc.id+"/order/latest/") 0217 if(props.cat_tree_filter=='filter_favourites') 0218 { 0219 catLink+='fav/1'; 0220 } 0221 return ( 0222 <a key={index} href={catLink} onClick={() => onHeaderNavigationItemClick(cvc,index)}> 0223 {cvc.title} 0224 </a> 0225 ) 0226 } 0227 }) 0228 } 0229 0230 let backButtonDisplay; 0231 if (props.showBackButton){ 0232 backButtonDisplay = <a id="back-button" onClick={props.onGoBackClick}><span className="glyphicon glyphicon-chevron-left"></span></a>; 0233 } else backButtonDisplay = <a id="back-button" className="disabled"><span className="glyphicon glyphicon-chevron-left"></span></a>; 0234 0235 let sNameDisplay; 0236 //if (props.showBreadCrumbs === true){ 0237 if (categories.length === 0){ 0238 if (props.storeInfo){ 0239 let storeName = window.config.sName, storeHref = window.config.sName; 0240 if (props.storeInfo.name.length > 0) storeName = props.storeInfo.name; 0241 if (props.storeInfo.menuhref.length > 0) storeHref = props.storeInfo.menuhref; 0242 if (props.cat_tree_filter=='filter_favourites'){ 0243 storeHref= storeHref+'/my-favourites'; 0244 } else { 0245 storeHref += "/browse"; 0246 } 0247 sNameDisplay = <a href={storeHref}>{storeName}</a> 0248 } 0249 } 0250 //} 0251 0252 let forwadButtonDisplay; 0253 if (props.showForwardButton === true) forwadButtonDisplay = <a id="forward-button" onClick={props.onGoForwardClick}><span className="glyphicon glyphicon-chevron-right"></span></a> 0254 0255 return ( 0256 <div id="category-tree-header"> 0257 {backButtonDisplay} 0258 {sNameDisplay} 0259 {categoryTreeHeaderNavigationDisplay} 0260 {forwadButtonDisplay} 0261 </div> 0262 ) 0263 } 0264 0265 function CategoryPanelsContainer(props){ 0266 0267 /* STATE */ 0268 0269 const rootListingPanel = {categoryId:0,categories:props.categoryTree} 0270 const storeListingPanel = {categoryId:-1,categories:[...window.json_store_for_tree]} 0271 let initialRootCategoryPanels = [rootListingPanel]; 0272 // if (isShowRealDomainAsUrl === 1) initialRootCategoryPanels = [storeListingPanel,rootListingPanel]; 0273 let initialPanelsValue = initialRootCategoryPanels; 0274 if (props.currentViewedCategories.length > 0) initialPanelsValue = initialRootCategoryPanels.concat(props.currentViewedCategories); 0275 const [ panels, setPanels ] = useState(initialPanelsValue); 0276 const [ containerWidth, setContainerWidth ] = useState(document.getElementById('category-tree-container').offsetWidth); 0277 const [ sliderWidth, setSliderWidth ] = useState(containerWidth * panels.length); 0278 const [ sliderHeight, setSliderHeight ] = useState(); 0279 let currentCategoryLevel = props.currentCategoryLevel; 0280 if (window.location.href === "https://www.pling.com/" || window.location.href === "https://www.pling.cc/") currentCategoryLevel = 0; 0281 let initialSliderPosition = currentCategoryLevel * containerWidth; 0282 const [ sliderPosition, setSliderPosition ] = useState(initialSliderPosition); 0283 let initialShowBackButtonValue = true; 0284 if (sliderPosition === 0) initialShowBackButtonValue = false; 0285 const [ showBackButton, setShowBackButton ] = useState(initialShowBackButtonValue); 0286 0287 const [ containerVisibility, setContainerVisibility ] = useState(false); 0288 0289 /* COMPONENT */ 0290 0291 React.useEffect(() => { 0292 0293 let showBack = true, showBreadCrumbs = true, showForward = false; 0294 let minSliderPosition = 0; 0295 if (props.storeInfo && props.storeInfo.is_show_in_menu === "0"){ 0296 if (window.location.href !== "https://www.pling.com/" || window.location.href !== "https://www.pling.cc/") minSliderPosition = containerWidth; 0297 } 0298 0299 if (sliderPosition === minSliderPosition){ 0300 showBack = false; 0301 showBreadCrumbs = false; 0302 if (panels.length > 1 && sliderPosition > 0) showBreadCrumbs = true; 0303 } 0304 0305 let maxSliderPosition = ( containerWidth * panels.length ) - containerWidth; 0306 if (sliderPosition !== maxSliderPosition) { 0307 showForward = true; 0308 } 0309 0310 if (window.location.href === "https://www.pling.com/" || window.location.href === "https://www.pling.cc/"){ 0311 showForward = false; 0312 } 0313 0314 props.onSetShowBackButton(showBack); 0315 props.onSetShowBreadCrumbs(showBreadCrumbs); 0316 props.onSetShowForwardButton(showForward); 0317 0318 },[sliderPosition]); 0319 0320 React.useEffect(() => { updateSlider() },[props.currentCategoryLevel,props.currentViewedCategories]) 0321 React.useEffect(() => { updatePanlesOnSearch() },[props.searchMode,props.searchPhrase]) 0322 0323 // update slider 0324 function updateSlider(){ 0325 /*const trimedPanelsArray = [...initialRootCategoryPanels,...props.currentViewedCategories]; 0326 if (props.searchMode === false ){ 0327 let currentCategoryLevel = props.currentCategoryLevel; 0328 if (isShowRealDomainAsUrl === 1 ) currentCategoryLevel = props.currentCategoryLevel + 1; 0329 trimedPanelsArray.length = currentCategoryLevel + 1; 0330 } 0331 setPanels(trimedPanelsArray); 0332 0333 const newSliderWidth = containerWidth * trimedPanelsArray.length; 0334 setSliderWidth(newSliderWidth);*/ 0335 0336 let currentCategoryLevel = props.currentCategoryLevel; 0337 let newSliderPosition = currentCategoryLevel * containerWidth; 0338 if (window.location.href === "https://www.pling.com/" || window.location.href === "https://www.pling.cc/"){ 0339 if (props.searchMode !== true) newSliderPosition = 0; 0340 } 0341 setSliderPosition(newSliderPosition); 0342 0343 let newShowBackButton = true; 0344 if (newSliderPosition === 0) newShowBackButton = false; 0345 setShowBackButton(newShowBackButton); 0346 } 0347 0348 // update panels on search 0349 function updatePanlesOnSearch(){ 0350 const newPanels = [...initialRootCategoryPanels,...props.currentViewedCategories]; 0351 const newSliderWidth = containerWidth * newPanels.length; 0352 setPanels(newPanels); 0353 setSliderWidth(newSliderWidth); 0354 } 0355 0356 // on category select 0357 function onCategorySelect(c,catLink){ 0358 0359 const newCurrentCategoryLevel = props.currentCategoryLevel + 1; 0360 0361 const trimedPanelsArray = panels; 0362 trimedPanelsArray.length = newCurrentCategoryLevel; 0363 const newPanels = [...trimedPanelsArray,{categoryId:c.id,categories:ConvertObjectToArray(c.children)}]; 0364 setPanels(newPanels); 0365 0366 const newSliderWidth = containerWidth * newPanels.length; 0367 setSliderWidth(newSliderWidth); 0368 0369 const newSliderPosition = newCurrentCategoryLevel * containerWidth; 0370 setSliderPosition(newSliderPosition); 0371 0372 let trimedCurrentViewedCategoriesArray = [] 0373 if (props.currentViewedCategories.length > 0) { 0374 trimedCurrentViewedCategoriesArray = props.currentViewedCategories; 0375 trimedCurrentViewedCategoriesArray.length = props.currentCategoryLevel; 0376 } 0377 0378 c.categories = ConvertObjectToArray(c.children) 0379 0380 const newCurrentViewedCategories = [ 0381 ...trimedCurrentViewedCategoriesArray, 0382 {...c, level:newCurrentCategoryLevel} 0383 ] 0384 0385 props.onCategoryPanleItemClick(newCurrentCategoryLevel,newCurrentViewedCategories,catLink) 0386 } 0387 0388 // on set slider height 0389 function onSetSliderHeight(height){ 0390 setContainerVisibility(true); 0391 setSliderHeight(height) 0392 } 0393 0394 /* RENDER */ 0395 0396 const categoryPanelsDislpay = panels.map((cp,index) => ( 0397 <CategoryPanel 0398 key={index} 0399 level={index} 0400 currentCategoryLevel={props.currentCategoryLevel} 0401 currentViewedCategories={props.currentViewedCategories} 0402 selectedCategoriesId={props.selectedCategoriesId} 0403 sliderPosition={sliderPosition} 0404 categories={cp.categories} 0405 parentCategory={cp.categoryId} 0406 categoryId={props.categoryId} 0407 containerWidth={containerWidth} 0408 searchMode={props.searchMode} 0409 searchPhrase={props.searchPhrase} 0410 onSetSliderHeight={(height) => onSetSliderHeight(height)} 0411 onCategorySelect={(c,catLink) => onCategorySelect(c,catLink)} 0412 cat_tree_filter={props.cat_tree_filter} 0413 /> 0414 )) 0415 0416 let categoryPanelsContainerCss = { 0417 height:sliderHeight+"px" 0418 } 0419 0420 let categoryPanelsSliderCss = { 0421 left:"-"+sliderPosition+"px", 0422 width:sliderWidth+"px", 0423 } 0424 0425 let categoryPanelsContainerClassName = ""; 0426 if (containerVisibility === true) categoryPanelsContainerClassName += "visible "; 0427 0428 return ( 0429 <div id="category-panles-container" className={categoryPanelsContainerClassName} style={categoryPanelsContainerCss}> 0430 <div id="category-panels-slider" style={categoryPanelsSliderCss}> 0431 {categoryPanelsDislpay} 0432 </div> 0433 </div> 0434 ) 0435 } 0436 0437 function CategoryPanel(props){ 0438 0439 function adjustSliderHeight(panelHeight){ 0440 let currentCategoryLevel = props.currentCategoryLevel 0441 /*if (isShowRealDomainAsUrl){ 0442 if (window.location.href !== "https://www.pling.com/" && window.location.href !== "https://www.pling.cc/") currentCategoryLevel = props.currentCategoryLevel + 1; 0443 }*/ 0444 if (currentCategoryLevel === props.level) props.onSetSliderHeight(panelHeight); 0445 } 0446 0447 function onSetCategoryPanelHeight(panelHeight){ 0448 adjustSliderHeight(panelHeight + 25); 0449 } 0450 0451 let panelCategories = props.categories; 0452 if (props.parentCategory === "-1"){ 0453 if (props.currentViewedCategories && props.currentViewedCategories.length > 0) panelCategories = props.currentViewedCategories[props.currentViewedCategories.length - 1].categories; 0454 } 0455 0456 let categoryPanelContent; 0457 if (panelCategories){ 0458 let categories; 0459 if (panelCategories.length > 0){ 0460 categories = panelCategories.sort(sortArrayAlphabeticallyByTitle); 0461 let itemIndex = 0; 0462 categories = categories.map((c,index) =>{ 0463 let showCategory = true; 0464 if (c.is_show_in_menu && c.is_show_in_menu === "0") showCategory = false; 0465 if (showCategory === true){ 0466 itemIndex += 1; 0467 if (categories.length === (index + 1)) onSetCategoryPanelHeight(itemIndex * 25); 0468 return ( 0469 <CategoryMenuItem 0470 key={index} 0471 category={c} 0472 categoryId={props.categoryId} 0473 parentCategory={props.parentCategory} 0474 currentViewedCategories={props.currentViewedCategories} 0475 selectedCategoriesId={props.selectedCategoriesId} 0476 onCategoryClick={(c,catLink) => props.onCategorySelect(c,catLink)} 0477 searchMode={props.searchMode} 0478 searchPhrase={props.searchPhrase} 0479 cat_tree_filter={props.cat_tree_filter} 0480 /> 0481 ) 0482 } 0483 }) 0484 } else { 0485 categories = <li><p>no categories matching {props.searchPhrase}</p></li> 0486 } 0487 categoryPanelContent = <ul>{categories}</ul> 0488 } 0489 0490 const categoryPanelCss = { 0491 width:props.containerWidth, 0492 float:"left" 0493 } 0494 0495 return( 0496 <div className="category-panel" id={"panel-"+props.level} style={categoryPanelCss}> 0497 {categoryPanelContent} 0498 </div> 0499 ) 0500 } 0501 0502 function CategoryMenuItem(props){ 0503 0504 const c = props.category; 0505 0506 function onCategoryClick(c,catLink){ 0507 setTimeout(() => { 0508 if (c.has_children === true) props.onCategoryClick(c,catLink) 0509 }, 100); 0510 } 0511 0512 let catLink; 0513 if (c.id){ 0514 if (c.id === "0"){ 0515 catLink = window.config.baseUrl; 0516 if (window.config.baseUrl.indexOf('http') === -1) catLink = "https://" + window.config.baseUrl; 0517 } 0518 else { 0519 catLink = getUrlContext(window.location.href); 0520 catLink += c.id === "00" ? "/browse/" : "/browse/cat/"+c.id+"/order/latest/"; 0521 } 0522 } 0523 else { 0524 if (c.menuhref.indexOf('http') > -1) catLink = c.menuhref; 0525 else catLink = "https://" + c.menuhref; 0526 } 0527 0528 let catTitle; 0529 if (c.title) catTitle = c.title; 0530 else catTitle = c.name; 0531 0532 if (catTitle === "ALL" && props.parentCategory === -1) catLink += "/browse/"; 0533 0534 if(props.cat_tree_filter=='filter_favourites') 0535 { 0536 catLink+='fav/1'; 0537 } 0538 const categoryMenuItemDisplay = ( 0539 <a href={catLink} onClick={() => onCategoryClick(c,catLink)}> 0540 <span className="cat-title">{catTitle}</span> 0541 <span className="cat-product-counter">{c.product_count}</span> 0542 </a> 0543 ) 0544 0545 let categoryMenuItemClassName; 0546 if (c.id === "0"){ 0547 if (window.location.href === catLink || window.location.href === catLink + "/"){ 0548 categoryMenuItemClassName = "active"; 0549 } 0550 } else if (c.id === "00") { 0551 let baseName = window.config.sName; 0552 if (window.config.sName.indexOf('http') === -1 ) baseName = "https://" + window.config.sName; 0553 if (window.location.href === window.config.baseUrl + catLink || window.location.href === window.config.baseUrl + catLink.split("/browse")[0] || 0554 window.location.href === baseName + catLink || window.location.href === baseName + catLink.split("/browse")[0]){ 0555 categoryMenuItemClassName = "active"; 0556 } 0557 } else { 0558 if (c.id && props.categoryId === parseInt(c.id) || props.selectedCategoriesId.indexOf(c.id) > -1 || window.location.href === catLink || window.location.href === catLink + "/") categoryMenuItemClassName = "active"; 0559 } 0560 if (catTitle === json_store_name) categoryMenuItemClassName = "active"; 0561 return( 0562 <li className={categoryMenuItemClassName} > 0563 {categoryMenuItemDisplay} 0564 </li> 0565 ) 0566 } 0567 0568 function CategoryTagCloud(props){ 0569 0570 const [ tags, setTags ] = useState(); 0571 0572 React.useEffect(() => { getCategoryTags() },[]) 0573 React.useEffect(() => { getCategoryTags() },[props.selectedCategory]) 0574 0575 function getCategoryTags(){ 0576 0577 let baseAjaxUrl = "https://www.pling." 0578 if (window.location.host.endsWith('com') || window.location.host.endsWith('org')){ 0579 baseAjaxUrl += "com"; 0580 } else { 0581 baseAjaxUrl += "cc"; 0582 } 0583 0584 let url = baseAjaxUrl + "/json/cattags/id/" + props.selectedCategory.id; 0585 $.ajax({ 0586 dataType: "json", 0587 url: url, 0588 success: function(res){ 0589 setTags(res); 0590 } 0591 }); 0592 } 0593 0594 let tagsDisplay; 0595 if (tags){ 0596 tagsDisplay = tags.map((t,index) => ( 0597 <a key={index} href={"http://" + window.location.host + "/search?projectSearchText="+t.tag_fullname+"&f=tags"}> 0598 <span className="glyphicon glyphicon-tag"></span> 0599 {t.tag_name} 0600 </a> 0601 )) 0602 } 0603 0604 return ( 0605 <div id="category-tag-cloud"> 0606 {tagsDisplay} 0607 </div> 0608 ) 0609 } 0610 0611 const rootElement = document.getElementById("category-tree-container"); 0612 ReactDOM.render(<CategoryTree />, rootElement);