Don't display the answering "Move On" button until the server reports idle
authorCarl Worth <cworth@cworth.org>
Sun, 14 Jun 2020 23:43:49 +0000 (16:43 -0700)
committerCarl Worth <cworth@cworth.org>
Sun, 14 Jun 2020 23:43:49 +0000 (16:43 -0700)
By waiting until the server reports that things are idle, it's safer
to display this button. (Displaying it early might result in a a user
being considered a majority of just the group of that player alone,
which is not what is desired.)

empathy/empathy.jsx

index 80069426d941666e2a812434bef72d2663995bbf..683f92d9318a6afa6628fd238edacccf9f90f183 100644 (file)
@@ -67,6 +67,8 @@ events.addEventListener("game-state", event => {
 
   window.game.set_players_answering(state.players_answering);
 
+  window.game.set_answering_idle(state.answering_idle);
+
   window.game.set_end_answers(state.end_answers);
 
   window.game.set_ambiguities(state.ambiguities);
@@ -104,6 +106,12 @@ events.addEventListener("player-answering", event => {
   window.game.set_player_answering(player);
 });
 
+events.addEventListener("answering-idle", event => {
+  const value = JSON.parse(event.data);
+
+  window.game.set_answering_idle(value);
+});
+
 events.addEventListener("vote-end-answers", event => {
   const player = JSON.parse(event.data);
 
@@ -656,6 +664,30 @@ class ActivePrompt extends React.PureComponent {
   }
 
   render() {
+    let move_on_button = null;
+    if (this.props.idle) {
+      move_on_button =(
+        <button
+          className="vote-button"
+          onClick={() => fetch_post_json(`end-answers/${this.props.prompt.id}`) }
+        >
+          Move On
+          <div className="vote-choices">
+            {[...this.props.votes].map(v => {
+              return (
+                <div
+                  key={v}
+                  className="vote-choice"
+                >
+                  {v}
+                </div>
+              );
+            })}
+          </div>
+        </button>
+      );
+    }
+
     if (this.props.players_answered.has(this.props.player.name)) {
       return (
         <div className="please-wait">
@@ -680,24 +712,7 @@ class ActivePrompt extends React.PureComponent {
               );
             })}
           </ul>
-          <button
-            className="vote-button"
-            onClick={() => fetch_post_json(`end-answers/${this.props.prompt.id}`) }
-          >
-            Move On
-            <div className="vote-choices">
-              {[...this.props.votes].map(v => {
-                return (
-                  <div
-                    key={v}
-                    className="vote-choice"
-                  >
-                    {v}
-                  </div>
-                );
-              })}
-            </div>
-          </button>
+          {move_on_button}
 
         </div>
       );
@@ -755,6 +770,7 @@ class Game extends React.PureComponent {
       active_prompt: null,
       players_answered: new Set(),
       players_answering: {},
+      answering_idle: false,
       end_answers_votes: new Set(),
       ambiguities: null,
       players_judged: new Set(),
@@ -795,6 +811,7 @@ class Game extends React.PureComponent {
       active_prompt: null,
       players_answered: new Set(),
       players_answering: {},
+      answering_idle: false,
       end_answers_votes: new Set(),
       ambiguities: null,
       players_judged: new Set(),
@@ -864,6 +881,12 @@ class Game extends React.PureComponent {
     });
   }
 
+  set_answering_idle(value) {
+    this.setState({
+      answering_idle: value
+    });
+  }
+
   set_end_answers(players) {
     this.setState({
       end_answers_votes: new Set(players)
@@ -1001,6 +1024,7 @@ class Game extends React.PureComponent {
                player={state.player_info}
                players_answered={state.players_answered}
                players_answering={state.players_answering}
+               idle={state.answering_idle}
                votes={state.end_answers_votes}
              />;
     }