Skip to content

Instantly share code, notes, and snippets.

@Jtmaca9
Created February 19, 2016 02:30
Show Gist options
  • Save Jtmaca9/820568b0a5b4c11f1d3f to your computer and use it in GitHub Desktop.
Save Jtmaca9/820568b0a5b4c11f1d3f to your computer and use it in GitHub Desktop.
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