Put commas back into players' overall scores list
authorCarl Worth <cworth@cworth.org>
Thu, 18 Jun 2020 18:54:09 +0000 (11:54 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 18 Jun 2020 18:54:09 +0000 (11:54 -0700)
I keep learning that the less logic there is in JSX, the better.

empathy/empathy.jsx

index 82bb5ff681989470aa2a78e10d9f7eedc5f42d51..0c1fccfe0b60e1a399c2d2bf2c27082c46c1c5eb 100644 (file)
@@ -205,20 +205,23 @@ const PlayerInfo = React.memo(props => {
   if (! props.player.id)
     return null;
 
-  const sorted_players = [props.player, ...props.other_players].sort((a,b) => {
+  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>
-      {sorted_players.map(player => (
-        <span key={player.id}>
-          {player.name}
-          {player.score > 0 ? ` (${player.score})` : ""}
-          {" "}
-        </span>
-      ))}
+      <span>{names_and_scores}</span>
     </div>
   );
 });