mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2025-04-25 00:41:07 +00:00
Make map votes togglable
This commit is contained in:
parent
d70240ddec
commit
cc95d9789e
4 changed files with 29 additions and 36 deletions
|
@ -323,7 +323,7 @@ Gather.prototype.toJson = function () {
|
||||||
};
|
};
|
||||||
|
|
||||||
Gather.prototype.voteForMap = function (voter, mapId) {
|
Gather.prototype.voteForMap = function (voter, mapId) {
|
||||||
this.modifyGatherer(voter, gatherer => gatherer.voteForMap(mapId));
|
this.modifyGatherer(voter, gatherer => gatherer.toggleMapVote(mapId));
|
||||||
};
|
};
|
||||||
|
|
||||||
Gather.prototype.voteForServer = function (voter, serverId) {
|
Gather.prototype.voteForServer = function (voter, serverId) {
|
||||||
|
|
|
@ -27,8 +27,11 @@ function Gatherer (user) {
|
||||||
this.regatherVote = false;
|
this.regatherVote = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
Gatherer.prototype.voteForMap = function (mapId) {
|
Gatherer.prototype.toggleMapVote = function (mapId) {
|
||||||
if (this.mapVote.some(votedId => votedId === mapId)) return;
|
if (this.mapVote.some(votedId => votedId === mapId)) {
|
||||||
|
this.mapVote = this.mapVote.filter(voteId => voteId !== mapId)
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.mapVote.push(mapId);
|
this.mapVote.push(mapId);
|
||||||
this.mapVote = this.mapVote.slice(this.mapVote.length - MAX_MAP_VOTES,
|
this.mapVote = this.mapVote.slice(this.mapVote.length - MAX_MAP_VOTES,
|
||||||
this.mapVote.length);
|
this.mapVote.length);
|
||||||
|
|
|
@ -570,27 +570,17 @@ var MapVoting = React.createClass({
|
||||||
return bVotes - aVotes;
|
return bVotes - aVotes;
|
||||||
}).map(map => {
|
}).map(map => {
|
||||||
let votes = self.votesForMap(map);
|
let votes = self.votesForMap(map);
|
||||||
if (thisGatherer.mapVote.some(voteId => voteId === map.id)) {
|
let style = thisGatherer.mapVote.some(voteId => voteId === map.id) ?
|
||||||
return (
|
"list-group-item list-group-item-success" : "list-group-item";
|
||||||
<a href="#"
|
return (
|
||||||
key={map.id}
|
<a href="#"
|
||||||
onClick={ e => e.preventDefault() }
|
key={map.id}
|
||||||
className="list-group-item list-group-item-success">
|
onClick={self.voteHandler(map.id)}
|
||||||
<span className="badge">{votes}</span>
|
className={style}>
|
||||||
{map.name}
|
<span className="badge">{votes}</span>
|
||||||
</a>
|
{map.name}
|
||||||
);
|
</a>
|
||||||
} else {
|
);
|
||||||
return (
|
|
||||||
<a href="#"
|
|
||||||
key={map.id}
|
|
||||||
onClick={self.voteHandler(map.id)}
|
|
||||||
className="list-group-item">
|
|
||||||
<span className="badge">{votes}</span>
|
|
||||||
{map.name}
|
|
||||||
</a>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
let votes = thisGatherer.mapVote.length;
|
let votes = thisGatherer.mapVote.length;
|
||||||
|
|
|
@ -28,27 +28,27 @@ describe("Gather Model:", function () {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#voteForMap", function () {
|
describe("#toggleMapVote", function () {
|
||||||
it ("assigns vote for map id", function () {
|
it ("assigns vote for map id", function () {
|
||||||
assert.equal(gatherer.mapVote.length, 0);
|
assert.equal(gatherer.mapVote.length, 0);
|
||||||
gatherer.voteForMap(1);
|
gatherer.toggleMapVote(1);
|
||||||
assert.isTrue(gatherer.mapVote.some(voteId => voteId === 1));
|
assert.isTrue(gatherer.mapVote.some(voteId => voteId === 1));
|
||||||
});
|
});
|
||||||
it ("only assigns vote once", function () {
|
it ("removes map vote if toggled twice", function () {
|
||||||
gatherer.voteForMap(1);
|
gatherer.toggleMapVote(1);
|
||||||
gatherer.voteForMap(1);
|
gatherer.toggleMapVote(1);
|
||||||
assert.equal(gatherer.mapVote.length, 1);
|
assert.equal(gatherer.mapVote.length, 0);
|
||||||
});
|
});
|
||||||
it ("allows a maximum of 2 votes", function () {
|
it ("allows a maximum of 2 votes", function () {
|
||||||
gatherer.voteForMap(1);
|
gatherer.toggleMapVote(1);
|
||||||
gatherer.voteForMap(2);
|
gatherer.toggleMapVote(2);
|
||||||
gatherer.voteForMap(3);
|
gatherer.toggleMapVote(3);
|
||||||
assert.equal(gatherer.mapVote.length, 2);
|
assert.equal(gatherer.mapVote.length, 2);
|
||||||
});
|
});
|
||||||
it ("removes oldest vote if maximum vote exceeded", function () {
|
it ("removes oldest vote if maximum vote exceeded", function () {
|
||||||
gatherer.voteForMap(1);
|
gatherer.toggleMapVote(1);
|
||||||
gatherer.voteForMap(2);
|
gatherer.toggleMapVote(2);
|
||||||
gatherer.voteForMap(3);
|
gatherer.toggleMapVote(3);
|
||||||
assert.isFalse(gatherer.mapVote.some(voteId => voteId === 1));
|
assert.isFalse(gatherer.mapVote.some(voteId => voteId === 1));
|
||||||
assert.isTrue(gatherer.mapVote.some(voteId => voteId === 2));
|
assert.isTrue(gatherer.mapVote.some(voteId => voteId === 2));
|
||||||
assert.isTrue(gatherer.mapVote.some(voteId => voteId === 3));
|
assert.isTrue(gatherer.mapVote.some(voteId => voteId === 3));
|
||||||
|
|
Loading…
Reference in a new issue