File indexing completed on 2025-02-23 05:30:51
0001 import React, { Component } from 'react'; 0002 class Support extends Component { 0003 constructor(props){ 0004 super(props); 0005 this.state = {selected:'month'}; 0006 this.handleClick = this.handleClick.bind(this); 0007 this.tabSwitch = this.tabSwitch.bind(this); 0008 } 0009 0010 componentWillMount() { 0011 document.addEventListener('click',this.handleClick, false); 0012 } 0013 0014 componentWillUnmount() { 0015 document.removeEventListener('click',this.handleClick, false); 0016 } 0017 0018 0019 handleClick(e){ 0020 0021 let dropdownClass = ""; 0022 if (this.node.contains(e.target)){ 0023 if(e.target.className === "header-supporters" ) 0024 { 0025 // only btn click open dropdown 0026 if (this.state.dropdownClass === "open"){ 0027 dropdownClass = ""; 0028 }else{ 0029 dropdownClass = "open"; 0030 } 0031 }else{ 0032 dropdownClass = "open"; 0033 } 0034 } 0035 this.setState({dropdownClass:dropdownClass}); 0036 } 0037 0038 tabSwitch(selected) 0039 { 0040 this.setState({selected:selected}); 0041 } 0042 0043 render(){ 0044 let supporters; 0045 if(this.props.section.supporters) 0046 { 0047 const sectioncontainer = <div className="pling-nav-tabs"> 0048 <ul className="nav nav-tabs pling-section-tabs"> 0049 <li key={'month'} 0050 className={(this.state.selected=="month")?'active':''} 0051 onClick={()=>this.tabSwitch('month')} 0052 > 0053 <a className="cls-tab-month">Months</a> 0054 </li> 0055 </ul> 0056 <a href="/support" role="button" className="btn btn-primary active">Become a Supporter</a> 0057 </div> 0058 0059 // default show month panel 0060 let content = this.props.section.supporters.sort((a, b) => Number(a.active_months) < Number(b.active_months)).map((mg,i) => ( 0061 <div className="section"><div className="section-name"><a href={"/u/"+mg.username}><img src={mg.profile_image_url}></img></a> 0062 <span><a href={"/u/"+mg.username}>{mg.username}</a></span></div> 0063 <div className="section-value"> {mg.active_months+' months'}</div></div> 0064 )) 0065 0066 0067 const t = ( 0068 <div className="user-pling-section-container"> 0069 {sectioncontainer} 0070 { content } 0071 </div> 0072 ) 0073 0074 supporters = <ul className="dropdown-menu dropdown-menu-right">{t}</ul> 0075 } 0076 const s = this.props.section.supporters?this.props.section.supporters.length:0; 0077 return( 0078 <div className={"pling-section-header "+this.props.headerStyle}> 0079 <div className="header-body"> 0080 0081 <div ref={node => this.node = node} className={'supporter-container '+this.state.dropdownClass }> 0082 <a className="header-supporters" >{this.props.section ? this.props.section.name:''} has {s} active Supporters ⌄ </a> 0083 {supporters} 0084 </div> 0085 </div> 0086 </div> 0087 ) 0088 } 0089 } 0090 0091 export default Support;