]> git.cworth.org Git - lmno.games/commitdiff
empathy: Add button to hide/(vote against) categories
authorCarl Worth <cworth@cworth.org>
Sun, 28 Jun 2020 21:42:32 +0000 (14:42 -0700)
committerCarl Worth <cworth@cworth.org>
Sun, 28 Jun 2020 21:42:32 +0000 (14:42 -0700)
The server collects (and distributes) votes against but only the
client who voted against a category hides it.

empathy/empathy.css
empathy/empathy.jsx
style.css

index a58e63306e1c22d42c534653f8a3507ec0da80d4..36281bc3ab37d6f24d072bd3f152e37d9a28d5c2 100644 (file)
@@ -7,6 +7,7 @@
     font-size: 200%;
     padding: 1em;
     margin-bottom: 0.25em;
+    position: relative;
 }
 
 .vote-choices {
index 143acd930824a564af6a7153cbbd3b37006a54fc..ab45be913f109e782349529af805f8edd82105e1 100644 (file)
@@ -363,6 +363,50 @@ class CategoryRequest extends React.PureComponent {
   }
 }
 
+const PromptOption = React.memo(props => {
+
+  const prompt = props.prompt;
+  const [show_prompt, set_show_prompt] = React.useState(true);
+
+  if (! show_prompt)
+    return false;
+
+  if (prompt.votes_against.find(v => v === props.player.name))
+    return false;
+
+  return (
+    <button
+      className="vote-button"
+      key={prompt.id}
+      onClick={() => fetch_post_json(`vote/${prompt.id}`) }
+    >
+      <span
+        className="hide-button"
+        onClick={(event) => {
+          event.stopPropagation();
+          fetch_post_json(`vote_against/${prompt.id}`);
+          set_show_prompt(false);
+        }}
+      >
+        &times;
+      </span>
+      {prompt.prompt}
+      <div className="vote-choices">
+        {prompt.votes.map(v => {
+          return (
+            <div
+              key={v}
+              className="vote-choice"
+            >
+              {v}
+            </div>
+          );
+        })}
+      </div>
+    </button>
+  );
+});
+
 const PromptOptions = React.memo(props => {
 
   if (props.prompts.length === 0)
@@ -375,29 +419,7 @@ const PromptOptions = React.memo(props => {
         Select any categories below that you'd like to play.
         You can choose as many as you'd like.
       </p>
-      {props.prompts.map(p => {
-        return (
-          <button
-            className="vote-button"
-            key={p.id}
-            onClick={() => fetch_post_json(`vote/${p.id}`) }
-          >
-            {p.prompt}
-            <div className="vote-choices">
-              {p.votes.map(v => {
-                return (
-                  <div
-                    key={v}
-                    className="vote-choice"
-                  >
-                    {v}
-                  </div>
-                );
-              })}
-            </div>
-          </button>
-        );
-      })}
+    {props.prompts.map(p => <PromptOption prompt={p} player={props.player} />)}
     </div>
   );
 });
@@ -1221,6 +1243,7 @@ class Game extends React.PureComponent {
       <PromptOptions
         key="prompts"
         prompts={state.prompts}
+        player={state.player_info}
       />,
       <LetsPlay
         key="lets-play"
index ff638f3950db7d3cf04733c15a039543da8b157b..bc611e5a16587f895e37be0864c5f6cc2b483454 100644 (file)
--- a/style.css
+++ b/style.css
@@ -338,6 +338,7 @@ button.inline {
 
 .hide-button {
     color: white;
+    opacity: 0.5;
     font-size: 125%;
     font-weight: bold;
     cursor: pointer;
@@ -348,7 +349,7 @@ button.inline {
 
 @media (hover:hover) {
     .hide-button:hover {
-        color: var(--danger-color-dark);
+        opacity: 1.0;
     }
 }