Created
February 19, 2016 02:30
-
-
Save Jtmaca9/820568b0a5b4c11f1d3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var React = require('react'); | |
var VoteWords = React.createClass({ | |
getInitialState: function(){ | |
return{ | |
votes: [] | |
} | |
}, | |
componentDidMount: function(){ | |
var self = this; | |
}, | |
handleClick: function(e){ | |
if(this.props.canVote && e.target.text == "End Story"){ | |
this.props.socket.emit('vote', '[END_STORY]'); | |
}else if(this.props.canVote){ | |
debugger; | |
this.props.socket.emit('vote', (e.target.parentElement.textContent).replace(/\d+/g,'')); | |
this.props.changeCanVote(false); | |
} | |
}, | |
renderVotes: function(votes, onclick){ | |
return votes.map(function(vote) { | |
return <a className="btn btn-primary" key={vote.id} onClick={onclick}>{vote.word}<span className="badge">{vote.count}</span></a> | |
}); | |
}, | |
render: function(){ | |
return ( | |
<div> | |
<a className="btn btn-danger" onClick={this.handleClick}>End Story<span className="badge"></span></a> | |
{this.renderVotes(this.props.voteWords, this.handleClick)} | |
</div> | |
) | |
} | |
}); | |
module.exports = VoteWords; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment