]> git.cworth.org Git - lmno.games/blobdiff - empathy/empathy.jsx
Drop an unneeded function
[lmno.games] / empathy / empathy.jsx
index b69ce6f15c3d090e178b27e78e89686a2e7051a1..110b330a71142a5de6c27ee0bd567a1c5abf0591 100644 (file)
@@ -80,7 +80,7 @@ function copy_to_clipboard(id)
   document.body.removeChild(tmp);
 }
 
-function GameInfo(props) {
+const GameInfo = React.memo(props => {
   if (! props.id)
     return null;
 
@@ -97,9 +97,9 @@ function GameInfo(props) {
       >Copy Link</button>
     </div>
   );
-}
+});
 
-function PlayerInfo(props) {
+const PlayerInfo = React.memo(props => {
   if (! props.player.id)
     return null;
 
@@ -115,7 +115,7 @@ function PlayerInfo(props) {
       ))}
     </div>
   );
-}
+});
 
 function fetch_method_json(method, api = '', data = {}) {
   const response = fetch(api, {
@@ -136,7 +136,7 @@ async function fetch_put_json(api = '', data = {}) {
   return fetch_method_json('PUT', api, data);
 }
 
-class CategoryRequest extends React.Component {
+class CategoryRequest extends React.PureComponent {
   constructor(props) {
     super(props);
     this.category = React.createRef();
@@ -210,11 +210,7 @@ class CategoryRequest extends React.Component {
   }
 }
 
-function PromptOptions(props) {
-
-  function handle_click(id) {
-    fetch_post_json(`vote/${id}`);
-  }
+const PromptOptions = React.memo(props => {
 
   if (props.prompts.length === 0)
     return null;
@@ -231,7 +227,7 @@ function PromptOptions(props) {
           <button
             className="vote-button"
             key={p.id}
-            onClick={() => handle_click(p.id)}
+            onClick={() => fetch_post_json(`vote/${p.id}`) }
           >
             {p.prompt}
             <div className="vote-choices">
@@ -251,9 +247,9 @@ function PromptOptions(props) {
       })}
     </div>
   );
-}
+});
 
-class Game extends React.Component {
+class Game extends React.PureComponent {
   constructor(props) {
     super(props);
     this.state = {