+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 form = event.currentTarget;
+ const category_input = this.category.current;
+ const category = category_input.value;
+
+ /* Prevent the default page-changing form-submission behavior. */
+ event.preventDefault();
+
+ const match = category.match(/[0-9]+/);
+ if (match === null) {
+ category_input.setCustomValidity("Category must include a number");
+ form.reportValidity();
+ return;
+ }
+
+ fetch_post_json("prompts", {
+ items: parseInt(match[0], 10),
+ prompt: category
+ });
+
+ form.reset();
+ }
+
+ render() {
+ return (
+ <div className="category-request">
+ <h2>Submit a Category</h2>
+ <p>
+ Suggest a category to play. Don't forget to include the
+ number of items for each person to submit.
+ </p>
+
+ <form onSubmit={this.handle_submit} >
+ <div className="form-field large">
+ <input
+ type="text"
+ id="category"
+ placeholder="6 things at the beach"
+ required
+ autoComplete="off"
+ onChange={this.handle_change}
+ ref={this.category}
+ />
+ </div>
+
+ <div className="form-field large">
+ <button type="submit">
+ Send
+ </button>
+ </div>
+
+ </form>
+ </div>
+ );
+ }
+}
+
+function PromptOptions(props) {
+
+ function handle_click(id) {
+ fetch_post_json(`vote/${id}`);
+ }
+
+ if (props.prompts.length === 0)
+ return null;
+