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