]> git.cworth.org Git - lmno.games/blobdiff - empathy/empathy.jsx
Use triple-equals instead of double
[lmno.games] / empathy / empathy.jsx
index b03d697ef1cfd2561ffc1b223d4939e3b616fa4a..6f051f484f3ca3dfc71a21835ac787360192f434 100644 (file)
@@ -55,9 +55,7 @@ events.addEventListener("player-update", event => {
 events.addEventListener("game-state", event => {
   const state = JSON.parse(event.data);
 
-  for (let prompt of state.prompts) {
-    window.game.add_or_update_prompt(prompt);
-  }
+  window.game.set_prompts(state.prompts);
 
   window.game.set_active_prompt(state.active_prompt);
 
@@ -129,10 +127,12 @@ const PlayerInfo = React.memo(props => {
     <div className="player-info">
       <span className="players-header">Players: </span>
       {props.player.name}
+      {props.player.score > 0 ? ` (${props.player.score})` : ""}
       {props.other_players.map(other => (
         <span key={other.id}>
           {", "}
           {other.name}
+          {other.score > 0 ? ` (${other.score})` : ""}
         </span>
       ))}
     </div>
@@ -328,7 +328,7 @@ class ActivePrompt extends React.PureComponent {
     const response = await fetch_post_json(`answer/${this.props.prompt.id}`, {
       answers: this.answers.map(r => r.current.value)
     });
-    if (response.status == 200) {
+    if (response.status === 200) {
       const result = await response.json();
       if (! result.valid) {
         add_message("danger", result.message);
@@ -368,7 +368,7 @@ class ActivePrompt extends React.PureComponent {
         </p>
         <h2>{this.props.prompt.prompt}</h2>
         <form onSubmit={this.handle_submit}>
-          {Array(this.props.prompt.items).fill(null).map((whocares,i) => {
+          {[...Array(this.props.prompt.items)].map((whocares,i) => {
             return (
               <div
                 key={i}
@@ -436,6 +436,12 @@ class Game extends React.PureComponent {
     });
   }
 
+  set_prompts(prompts) {
+    this.setState({
+      prompts: prompts
+    });
+  }
+
   add_or_update_prompt(prompt) {
     const prompts_copy = [...this.state.prompts];
     const idx = prompts_copy.findIndex(p => p.id === prompt.id);