Advertisement
Guest User

Untitled

a guest
Dec 21st, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ProjectCard extends React.Component<void, Props, State> {
  2.   props: Props;
  3.   state: State;
  4.  
  5.   constructor (props: Props) {
  6.     super(props);
  7.     this.state = {
  8.       isActive: true,
  9.       isLocked: false
  10.     };
  11.   }
  12.  
  13.   componentDidMount() {
  14.     console.log("start mount");
  15.     console.log(this);
  16.    
  17.     this.onClick = this.onClick.bind(this);
  18.     this.toggleLock = this.toggleLock.bind(this);
  19.     this.toggleActive = this.toggleActive.bind(this);
  20.     console.log("mounted, functions bound");
  21.     //console.log(this.toggleActive);
  22.     this.toggleActive();
  23.     //manual fix, stackoverflow this.
  24.   }
  25.  
  26.   componentWillUnmount() {
  27.   }
  28.  
  29.   onClick () {
  30.     window.location.href = this.props.href;
  31.   }
  32.  
  33.   toggleLock () {
  34.     this.setState({
  35.       isLocked: !this.state.isLocked
  36.     });
  37.   }
  38.  
  39.   toggleActive () {
  40.     console.log("toggling");
  41.     console.log(this);
  42.     this.setState({
  43.       isActive: !this.state.isActive
  44.     });
  45.   }
  46.  
  47.   render (): React.Element<any> {
  48.     const { name, date, img, href, options } = this.props;
  49.     const { isActive, isLocked } = this.state;
  50.     const wrapStyle = Object.assign({}, styles.wrap,
  51.                     isActive || isLocked ? styles.wrapHover : styles.wrapNoHover);
  52.     const topStyle = Object.assign({}, styles.top,
  53.                    isActive || isLocked ? styles.topHover : styles.topNoHover);
  54.     return (
  55.       <div style={wrapStyle}
  56.        onMouseEnter={this.toggleActive}
  57.        onMouseLeave={this.toggleActive}
  58.        key={`project${href}Wrap`}>
  59.     <div style={topStyle}
  60.          onClick={this.onClick}
  61.          key={`project${href}Top`}>
  62.       <img src={img}/>
  63.     </div>
  64.     <div style={styles.bottom}>
  65.       <div style={styles.firstRow}>
  66.             <!-- redacted -->
  67.       </div>
  68.     </div>
  69.       </div>
  70.     );
  71.   }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement