X-Git-Url: https://git.cworth.org/git?p=lmno.games;a=blobdiff_plain;f=empathy%2Fempathy.jsx;h=1ee8000ab09376e7557b2dcdcdee3d844bde1963;hp=9ebe9f3c7a7b4afd604ee3159cc35ea7348a1677;hb=b0b2d2d5dd5c3bac29537e2f5b206208f0a43898;hpb=53c8c6ba09301563293750e1010ca1ac8dd05590 diff --git a/empathy/empathy.jsx b/empathy/empathy.jsx index 9ebe9f3..1ee8000 100644 --- a/empathy/empathy.jsx +++ b/empathy/empathy.jsx @@ -122,36 +122,70 @@ async function fetch_put_json(api = '', data = {}) { return fetch_method_json('PUT', api, data); } -function CategoryRequest(props) { - return ( -
-

Submit a Category

-

+class CategoryRequest extends React.Component { + constructor(props) { + super(props); + this.category = React.createRef(); + + this.handle_change = this.handle_change.bind(this); + this.handle_submit = this.handle_submit.bind(this); + } + + handle_change(event) { + const category_input = this.category.current; + const category = category_input.value; + + if (/[0-9]/.test(category)) + category_input.setCustomValidity(""); + } + + handle_submit(event) { + const category_input = this.category.current; + const category = category_input.value; + + /* Prevent the default page-changing form-submission behavior. */ + event.preventDefault(); + + if (! /[0-9]/.test(category)) { + category_input.setCustomValidity("Category must include a number"); + event.currentTarget.reportValidity(); + return; + } + + console.log("Do something here with category: " + category); + } + + render() { + return ( +

+

Submit a Category

+

Suggest a category to play with your friends. Don't forget to include the number of items for each person to submit. -

- -
-
- - -
- -
- -
- -
-
- ); +

+ +
+
+ +
+ +
+ +
+ +
+
+ ); + } } class Game extends React.Component {