Wait for judging phase to be idle before displaying "Move On" button
authorCarl Worth <cworth@cworth.org>
Thu, 18 Jun 2020 16:07:11 +0000 (09:07 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 18 Jun 2020 16:07:11 +0000 (09:07 -0700)
Just as we already do for the answering phase.

empathy/empathy.jsx

index 683f92d9318a6afa6628fd238edacccf9f90f183..e67bbc87afbc91941c7460bb52aeb865aeac0d5b 100644 (file)
@@ -77,6 +77,8 @@ events.addEventListener("game-state", event => {
 
   window.game.set_players_judging(state.players_judging);
 
+  window.game.set_judging_idle(state.judging_idle);
+
   window.game.set_end_judging(state.end_judging);
 
   window.game.set_scores(state.scores);
@@ -142,6 +144,12 @@ events.addEventListener("player-judging", event => {
   window.game.set_player_judging(player);
 });
 
+events.addEventListener("judging-idle", event => {
+  const value = JSON.parse(event.data);
+
+  window.game.set_judging_idle(value);
+});
+
 events.addEventListener("vote-end-judging", event => {
   const player = JSON.parse(event.data);
 
@@ -509,6 +517,31 @@ class Ambiguities 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-judging/${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_judged.has(this.props.player.name)) {
       return (
         <div className="please-wait">
@@ -533,24 +566,7 @@ class Ambiguities extends React.PureComponent {
               );
             })}
           </ul>
-          <button
-            className="vote-button"
-            onClick={() => fetch_post_json(`end-judging/${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>
       );
@@ -775,6 +791,7 @@ class Game extends React.PureComponent {
       ambiguities: null,
       players_judged: new Set(),
       players_judging: {},
+      judging_idle: false,
       end_judging_votes: new Set(),
       scores: null
     };
@@ -816,6 +833,7 @@ class Game extends React.PureComponent {
       ambiguities: null,
       players_judged: new Set(),
       players_judging: {},
+      judging_idle: false,
       end_judging_votes: new Set(),
       scores: null
     });
@@ -946,6 +964,13 @@ class Game extends React.PureComponent {
     });
   }
 
+  set_judging_idle(value) {
+    console.log("Setting judging idle to " + value);
+    this.setState({
+      judging_idle: value
+    });
+  }
+
   set_end_judging(players) {
     this.setState({
       end_judging_votes: new Set(players)
@@ -1014,6 +1039,7 @@ class Game extends React.PureComponent {
                player={state.player_info}
                players_judged={state.players_judged}
                players_judging={state.players_judging}
+               idle={state.judging_idle}
                votes={state.end_judging_votes}
              />;
     }