]> git.cworth.org Git - lmno.games/blobdiff - scribe/scribe.jsx
Use an array spread syntax instead of .fill(null)
[lmno.games] / scribe / scribe.jsx
index d81932b7b847e6bb813993fd06a20a336a90d0ec..78155949f782174a6ff40d2a80c7b5948f715868 100644 (file)
@@ -1,8 +1,8 @@
 function team_symbol(team) {
   if (team === "+")
-    return "🞥";
+    return "+";
   else
-    return "🞇";
+    return "o";
 }
 
 function undisplay(element) {
@@ -26,7 +26,9 @@ const events = new EventSource("events");
 
 events.onerror = function(event) {
   if (event.target.readyState === EventSource.CLOSED) {
+    setTimeout(() => {
       add_message("danger", "Connection to server lost.");
+    }, 1000);
   }
 };
 
@@ -77,14 +79,31 @@ events.addEventListener("game-state", event => {
  * Game and supporting classes                           *
  *********************************************************/
 
+function copy_to_clipboard(id)
+{
+  const tmp = document.createElement("input");
+  tmp.setAttribute("value", document.getElementById(id).innerHTML);
+  document.body.appendChild(tmp);
+  tmp.select();
+  document.execCommand("copy");
+  document.body.removeChild(tmp);
+}
+
 function GameInfo(props) {
   if (! props.id)
     return null;
 
   return (
     <div className="game-info">
-      <h2>{props.id}</h2>
-      Invite a friend to play by sending this URL: {props.url}
+      <span className="game-id">{props.id}</span>
+      {" "}
+      Share this link to invite a friend:{" "}
+      <span id="game-share-url">{props.url}</span>
+      {" "}
+      <button
+        className="inline"
+        onClick={() => copy_to_clipboard('game-share-url')}
+      >Copy Link</button>
     </div>
   );
 }
@@ -130,7 +149,7 @@ function PlayerInfo(props) {
 
   return (
     <div className="player-info">
-      <h2>Players</h2>
+      <span className="players-header">Players: </span>
       {props.player.name}
       {props.player.team ? ` (${props.player.team})` : ""}
       {props.first_move ? "" : " "}
@@ -249,7 +268,7 @@ class Game extends React.Component {
       game_info: {},
       player_info: {},
       other_players: [],
-      squares: Array(9).fill(null).map(() => Array(9).fill(null)),
+      squares: [...Array(9)].map(() => Array(9).fill(null)),
       moves: 0,
       next_to_play: "+"
     };