]> git.cworth.org Git - lmno.games/blobdiff - empathy/empathy.jsx
Put commas back into players' overall scores list
[lmno.games] / empathy / empathy.jsx
index e67bbc87afbc91941c7460bb52aeb865aeac0d5b..0c1fccfe0b60e1a399c2d2bf2c27082c46c1c5eb 100644 (file)
@@ -205,18 +205,23 @@ const PlayerInfo = React.memo(props => {
   if (! props.player.id)
     return null;
 
+  const all_players = [props.player, ...props.other_players];
+
+  const sorted_players = all_players.sort((a,b) => {
+    return b.score - a.score;
+  });
+
+  const names_and_scores = sorted_players.map(player => {
+    if (player.score)
+      return `${player.name} (${player.score})`;
+    else
+      return player.name;
+  }).join(', ');
+
   return (
     <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>
-      ))}
+      <span>{names_and_scores}</span>
     </div>
   );
 });