mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2025-02-20 18:52:27 +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) {
|
||||
this.modifyGatherer(voter, gatherer => gatherer.voteForMap(mapId));
|
||||
this.modifyGatherer(voter, gatherer => gatherer.toggleMapVote(mapId));
|
||||
};
|
||||
|
||||
Gather.prototype.voteForServer = function (voter, serverId) {
|
||||
|
|
|
@ -27,8 +27,11 @@ function Gatherer (user) {
|
|||
this.regatherVote = false;
|
||||
};
|
||||
|
||||
Gatherer.prototype.voteForMap = function (mapId) {
|
||||
if (this.mapVote.some(votedId => votedId === mapId)) return;
|
||||
Gatherer.prototype.toggleMapVote = function (mapId) {
|
||||
if (this.mapVote.some(votedId => votedId === mapId)) {
|
||||
this.mapVote = this.mapVote.filter(voteId => voteId !== mapId)
|
||||
return;
|
||||
}
|
||||
this.mapVote.push(mapId);
|
||||
this.mapVote = this.mapVote.slice(this.mapVote.length - MAX_MAP_VOTES,
|
||||
this.mapVote.length);
|
||||
|
|
|
@ -570,27 +570,17 @@ var MapVoting = React.createClass({
|
|||
return bVotes - aVotes;
|
||||
}).map(map => {
|
||||
let votes = self.votesForMap(map);
|
||||
if (thisGatherer.mapVote.some(voteId => voteId === map.id)) {
|
||||
return (
|
||||
<a href="#"
|
||||
key={map.id}
|
||||
onClick={ e => e.preventDefault() }
|
||||
className="list-group-item list-group-item-success">
|
||||
<span className="badge">{votes}</span>
|
||||
{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 style = thisGatherer.mapVote.some(voteId => voteId === map.id) ?
|
||||
"list-group-item list-group-item-success" : "list-group-item";
|
||||
return (
|
||||
<a href="#"
|
||||
key={map.id}
|
||||
onClick={self.voteHandler(map.id)}
|
||||
className={style}>
|
||||
<span className="badge">{votes}</span>
|
||||
{map.name}
|
||||
</a>
|
||||
);
|
||||
});
|
||||
|
||||
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 () {
|
||||
assert.equal(gatherer.mapVote.length, 0);
|
||||
gatherer.voteForMap(1);
|
||||
gatherer.toggleMapVote(1);
|
||||
assert.isTrue(gatherer.mapVote.some(voteId => voteId === 1));
|
||||
});
|
||||
it ("only assigns vote once", function () {
|
||||
gatherer.voteForMap(1);
|
||||
gatherer.voteForMap(1);
|
||||
assert.equal(gatherer.mapVote.length, 1);
|
||||
it ("removes map vote if toggled twice", function () {
|
||||
gatherer.toggleMapVote(1);
|
||||
gatherer.toggleMapVote(1);
|
||||
assert.equal(gatherer.mapVote.length, 0);
|
||||
});
|
||||
it ("allows a maximum of 2 votes", function () {
|
||||
gatherer.voteForMap(1);
|
||||
gatherer.voteForMap(2);
|
||||
gatherer.voteForMap(3);
|
||||
gatherer.toggleMapVote(1);
|
||||
gatherer.toggleMapVote(2);
|
||||
gatherer.toggleMapVote(3);
|
||||
assert.equal(gatherer.mapVote.length, 2);
|
||||
});
|
||||
it ("removes oldest vote if maximum vote exceeded", function () {
|
||||
gatherer.voteForMap(1);
|
||||
gatherer.voteForMap(2);
|
||||
gatherer.voteForMap(3);
|
||||
gatherer.toggleMapVote(1);
|
||||
gatherer.toggleMapVote(2);
|
||||
gatherer.toggleMapVote(3);
|
||||
assert.isFalse(gatherer.mapVote.some(voteId => voteId === 1));
|
||||
assert.isTrue(gatherer.mapVote.some(voteId => voteId === 2));
|
||||
assert.isTrue(gatherer.mapVote.some(voteId => voteId === 3));
|
||||
|
|
Loading…
Reference in a new issue