]> git.cworth.org Git - empires-server/commitdiff
Empathy: Make a vote for a prompt toggle the vote
authorCarl Worth <cworth@cworth.org>
Tue, 9 Jun 2020 02:05:22 +0000 (19:05 -0700)
committerCarl Worth <cworth@cworth.org>
Tue, 9 Jun 2020 02:05:22 +0000 (19:05 -0700)
Since what else might it mean for a user to vote where they had
already voted?

empathy.js

index f2a6859ad3998cfa0d310c1e8c7e68f3818ef151..6fc926ff83b56991e22dde9ad4ad5635852601d1 100644 (file)
@@ -22,11 +22,11 @@ class Prompt {
     this.votes = [];
   }
 
-  add_vote(player_name) {
+  toggle_vote(player_name) {
     if (this.votes.find(v => v === player_name))
-      return;
-
-    this.votes.push(player_name);
+      this.votes = this.votes.filter(v => v !== player_name);
+    else
+      this.votes.push(player_name);
   }
 }
 
@@ -54,7 +54,7 @@ router.post('/vote/:prompt_id([0-9]+)', (request, response) => {
     return;
   }
 
-  prompt.add_vote(player.name);
+  prompt.toggle_vote(player.name);
 
   game.broadcast_event_object('prompt', prompt);