File indexing completed on 2025-01-26 05:27:59

0001 import React, { useState } from 'react';
0002 import TopProducts from './TopProducts';
0003 import TopCreators from './TopCreators';
0004 import Support from './Support';
0005 import Supporters from './Supporters';
0006 import Header from './Header';
0007 
0008 const PlingSection = () => {
0009   const [state, setState] = useState(window.data);
0010   const [products, setProducts] = useState(window.data.products);
0011   const [creators, setCreators] = useState(window.data.creators);
0012   const [sections, setSections] = useState(window.data.sections);
0013   const [supporters, setSupporters] = useState(window.data.supporters)
0014   const [section, setSection] = useState(window.data.section);
0015   const [details, setDetails] = useState(window.data.details);
0016   const [category, setCategory] = useState();
0017   const [showContent, setShowContent] = useState('overview');
0018   const [loading, setLoading] = useState(false);
0019 
0020   const loadData = section =>{
0021     let url = '/section/top?id='+section.section_id;
0022     fetch(url)
0023     .then(response => response.json())
0024     .then(data => {
0025       setLoading(false);
0026       setProducts(data.products);
0027       setCreators(data.creators);      
0028      });
0029   }
0030 
0031   const showDetail = sc =>{
0032       setShowContent(sc);      
0033       if(showContent=='overview'){ loadData(section);}
0034   }
0035 
0036   const onClickCategory = category=>{
0037      let url = '/section/topcat?cat_id='+category.project_category_id;
0038      fetch(url)
0039      .then(response => response.json())
0040      .then(data => {
0041       setLoading(false);  
0042       setShowContent('overview');       
0043       setProducts(data.products);
0044       setCreators(data.creators);    
0045       setCategory(category);      
0046     });        
0047   }
0048 
0049 
0050   // render
0051   let sectioncontainer, sectiondetail;
0052   //onClick={()=>handleClick(section)}
0053   if (sections){
0054       const t = sections.map((s,index) => (
0055         <li key={s.section_id}
0056           className={(section && section.section_id==s.section_id)?'active':''}
0057           >
0058            <a href={"/section?id="+s.section_id}>{s.name}</a>
0059         </li>
0060       ));
0061      sectioncontainer =  <div className="pling-nav-tabs">
0062                         <ul className="nav nav-tabs pling-section-tabs">{t}</ul>
0063                         </div>
0064     }
0065 
0066     let categories;
0067     if (details && section){
0068       categories = details.map((detail,index) => {
0069             if(detail.section_id==section.section_id)
0070             return <li key={index}><a onClick={() => onClickCategory(detail)}>{detail.title}</a></li>
0071       });
0072     }
0073 
0074     let detailContent;
0075     if(showContent=='supporters')
0076     {
0077       detailContent = <Supporters baseUrlStore={state.baseurlStore} supporters = {supporters}/>
0078     }else {
0079       detailContent = (<React.Fragment>
0080                   <TopProducts isAdmin={state.isAdmin} baseUrlStore={state.baseurlStore}
0081                         products={products} section={section} category={category}/>
0082 
0083                   <TopCreators isAdmin={state.isAdmin} creators={creators} section={section} category={category}
0084                       baseUrlStore={state.baseurlStore}
0085                       />
0086                 </React.Fragment>
0087                 )
0088     }
0089 
0090     sectiondetail = <div className="pling-section-detail">
0091                     { section &&
0092                       <div className="pling-section-detail-left">
0093                         <h2 className={showContent=='overview'?'focused':''}><a onClick={()=>showDetail('overview')}>Overview</a></h2>
0094                         <h2 className={showContent=='supporters'?'focused':''}><a onClick={()=>showDetail('supporters')}>Supporters</a></h2>
0095                         <h2 className={showContent=='categories'?'focused':''}><a onClick={()=>showDetail('overview')}>Categories</a></h2>
0096                         <ul className="pling-section-detail-ul">{categories}</ul>
0097                       </div>
0098                     }
0099                     <div className="pling-section-detail-middle">
0100                       {detailContent}
0101                     </div>
0102                     <div className="pling-section-detail-right">
0103                       <div className="btnSupporter">Become a Supporter</div>
0104                         { section &&
0105                       <Support baseUrlStore={state.baseurlStore} section={section}
0106                               supporters = {supporters}
0107                         />
0108                       }
0109                     </div>
0110                   </div>
0111 
0112 
0113   return (
0114     <>
0115        <Header section={section} isAdmin={state.isAdmin}
0116                supporters = {supporters}
0117          />
0118        {sectioncontainer}
0119        {sectiondetail}
0120       </>
0121   )
0122 }
0123 
0124 export default PlingSection
0125