]> git.cworth.org Git - lmno.games/commitdiff
Reject a category with a number of items of 0
authorCarl Worth <cworth@cworth.org>
Mon, 29 Jun 2020 15:27:07 +0000 (08:27 -0700)
committerCarl Worth <cworth@cworth.org>
Mon, 29 Jun 2020 15:27:07 +0000 (08:27 -0700)
Thanks to my nephews for poking holes at the implementation by feeding
some stressful input to the game.

empathy/empathy.jsx

index 0593b049a30e6a0811f355f1a044fd1e2cb84853..6acf526c3516da99cdf72f282c65ff5ad894a8be 100644 (file)
@@ -283,7 +283,7 @@ class CategoryRequest extends React.PureComponent {
     const match = category.match(/[0-9]+/);
     if (match) {
       const num_items = parseInt(match[0], 10);
     const match = category.match(/[0-9]+/);
     if (match) {
       const num_items = parseInt(match[0], 10);
-      if (num_items <= MAX_PROMPT_ITEMS)
+      if (num_items > 0 && num_items <= MAX_PROMPT_ITEMS)
         category_input.setCustomValidity("");
     }
   }
         category_input.setCustomValidity("");
     }
   }
@@ -311,6 +311,12 @@ class CategoryRequest extends React.PureComponent {
       return;
     }
 
       return;
     }
 
+    if (num_items < 1) {
+      category_input.setCustomValidity("Category must require at least one item.");
+      form.reportValidity();
+      return;
+    }
+
     const response = await fetch_post_json("prompts", {
       items: num_items,
       prompt: category
     const response = await fetch_post_json("prompts", {
       items: num_items,
       prompt: category