mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2025-01-31 13:30:37 +00:00
Add regather voting
This commit is contained in:
parent
6dc379f33f
commit
5f3885b765
3 changed files with 44 additions and 31 deletions
|
@ -143,6 +143,10 @@ module.exports = function (namespace) {
|
|||
gather.voteForServer(socket._user, data.server.id);
|
||||
}
|
||||
|
||||
if (typeof data.regather === 'boolean' && gather.can("regather")) {
|
||||
gather.regather(socket._user, data.regather);
|
||||
}
|
||||
|
||||
winston.info("Vote Data",
|
||||
JSON.stringify(socket._user),
|
||||
JSON.stringify(data));
|
||||
|
|
|
@ -21,6 +21,7 @@ function Gatherer (user) {
|
|||
this.user = user;
|
||||
this.leader = false;
|
||||
this.team = "lobby";
|
||||
this.regatherVote = false;
|
||||
}
|
||||
|
||||
Gatherer.prototype.voteForLeader = candidate => {
|
||||
|
@ -33,4 +34,13 @@ Gatherer.prototype.voteForLeader = candidate => {
|
|||
this.leaderVote = candidate.id;
|
||||
};
|
||||
|
||||
Gatherer.prototype.voteRegather = (vote) => {
|
||||
if (vote !== undefined && typeof vote === 'boolean') {
|
||||
return this.regatherVote = vote;
|
||||
} else {
|
||||
this.regatherVote = true;
|
||||
}
|
||||
return this.regatherVote;
|
||||
};
|
||||
|
||||
module.exports = Gatherer;
|
|
@ -298,14 +298,25 @@ var GatherActions = React.createClass({
|
|||
socket.emit("gather:leave");
|
||||
},
|
||||
|
||||
confirmTeam(e) {
|
||||
e.preventDefault();
|
||||
socket.emit("gather:select:confirm");
|
||||
voteRegather(e) {
|
||||
e.preventDefault(e);
|
||||
socket.emit("gather:vote", {
|
||||
regather: (e.target.value === "true")
|
||||
});
|
||||
},
|
||||
|
||||
regatherVotes() {
|
||||
if (!this.props.gather) return 0;
|
||||
return this.props.gather.gatherers.reduce((acc, gatherer) => {
|
||||
if (gatherer.regatherVote) acc++;
|
||||
return acc;
|
||||
}, 0);
|
||||
},
|
||||
|
||||
render() {
|
||||
var joinButton;
|
||||
if (this.props.currentGatherer) {
|
||||
var currentGatherer = this.props.currentGatherer;
|
||||
if (currentGatherer) {
|
||||
joinButton = (<li><button
|
||||
onClick={this.leaveGather}
|
||||
className="btn btn-danger">Leave Gather</button></li>);
|
||||
|
@ -317,33 +328,21 @@ var GatherActions = React.createClass({
|
|||
);
|
||||
}
|
||||
|
||||
var confirmTeam;
|
||||
if (this.props.currentGatherer &&
|
||||
this.props.currentGatherer.leader &&
|
||||
this.props.gather.state === 'selection' &&
|
||||
this.props.gather.gatherers.every(gatherer => gatherer.team !== 'lobby')) {
|
||||
if (this.props.currentGatherer.confirm) {
|
||||
confirmTeam = (
|
||||
<li>
|
||||
<button
|
||||
className="btn btn-default"
|
||||
data-disabled="true"
|
||||
>
|
||||
Confirmed
|
||||
</button>
|
||||
</li>
|
||||
);
|
||||
var regatherButton;
|
||||
if (currentGatherer) {
|
||||
let regatherVotes = this.regatherVotes();
|
||||
if (currentGatherer.regatherVote) {
|
||||
regatherButton = (
|
||||
<li><button
|
||||
value="false"
|
||||
onClick={this.voteRegather}
|
||||
className="btn btn-danger">{`Voted Regather (${regatherVotes}/6)`}</button></li>);
|
||||
} else {
|
||||
confirmTeam = (
|
||||
<li>
|
||||
<button
|
||||
className="btn btn-success"
|
||||
onClick={this.confirmTeam}
|
||||
>
|
||||
Confirm Team
|
||||
</button>
|
||||
</li>
|
||||
);
|
||||
regatherButton = (
|
||||
<li><button
|
||||
value="true"
|
||||
onClick={this.voteRegather}
|
||||
className="btn btn-danger">{`Vote Regather (${regatherVotes}/6)`}</button></li>);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -353,7 +352,7 @@ var GatherActions = React.createClass({
|
|||
<div className="text-right">
|
||||
<ul className="list-inline no-bottom">
|
||||
<TeamSpeakButton />
|
||||
{confirmTeam}
|
||||
{regatherButton}
|
||||
{joinButton}
|
||||
</ul>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue