Fix to use server-sent state for whether player has answered/judged
[lmno.games] / empathy / empathy.jsx
1 const MAX_PROMPT_ITEMS = 20;
2
3 function undisplay(element) {
4   element.style.display="none";
5 }
6
7 function add_message(severity, message) {
8   message = `<div class="message ${severity}" onclick="undisplay(this)">
9 <span class="hide-button" onclick="undisplay(this.parentElement)">&times;</span>
10 ${message}
11 </div>`;
12   const message_area = document.getElementById('message-area');
13   message_area.insertAdjacentHTML('beforeend', message);
14 }
15
16 /*********************************************************
17  * Handling server-sent event stream                     *
18  *********************************************************/
19
20 const events = new EventSource("events");
21
22 events.onerror = function(event) {
23   if (event.target.readyState === EventSource.CLOSED) {
24     setTimeout(() => {
25       add_message("danger", "Connection to server lost.");
26     }, 1000);
27   }
28 };
29
30 events.addEventListener("game-info", event => {
31   const info = JSON.parse(event.data);
32
33   window.game.set_game_info(info);
34 });
35
36 events.addEventListener("player-info", event => {
37   const info = JSON.parse(event.data);
38
39   window.game.set_player_info(info);
40 });
41
42 events.addEventListener("player-enter", event => {
43   const info = JSON.parse(event.data);
44
45   window.game.set_other_player_info(info);
46 });
47
48 events.addEventListener("player-update", event => {
49   const info = JSON.parse(event.data);
50
51   if (info.id === window.game.state.player_info.id)
52     window.game.set_player_info(info);
53   else
54     window.game.set_other_player_info(info);
55 });
56
57 events.addEventListener("game-state", event => {
58   const state = JSON.parse(event.data);
59
60   window.game.reset_game_state();
61
62   window.game.set_prompts(state.prompts);
63
64   window.game.set_active_prompt(state.active_prompt);
65
66   window.game.set_players_answered(state.players_answered);
67
68   window.game.set_players_answering(state.players_answering);
69
70   window.game.set_end_answers(state.end_answers);
71
72   window.game.set_ambiguities(state.ambiguities);
73
74   window.game.set_players_judged(state.players_judged);
75
76   window.game.set_players_judging(state.players_judging);
77
78   window.game.set_end_judging(state.end_judging);
79
80   window.game.set_scores(state.scores);
81 });
82
83 events.addEventListener("prompt", event => {
84   const prompt = JSON.parse(event.data);
85
86   window.game.add_or_update_prompt(prompt);
87 });
88
89 events.addEventListener("start", event => {
90   const prompt = JSON.parse(event.data);
91
92   window.game.set_active_prompt(prompt);
93 });
94
95 events.addEventListener("player-answered", event => {
96   const player = JSON.parse(event.data);
97
98   window.game.set_player_answered(player);
99 });
100
101 events.addEventListener("player-answering", event => {
102   const player = JSON.parse(event.data);
103
104   window.game.set_player_answering(player);
105 });
106
107 events.addEventListener("vote-end-answers", event => {
108   const player = JSON.parse(event.data);
109
110   window.game.set_player_vote_end_answers(player);
111 });
112
113 events.addEventListener("unvote-end-answers", event => {
114   const player = JSON.parse(event.data);
115
116   window.game.set_player_unvote_end_answers(player);
117 });
118
119 events.addEventListener("ambiguities", event => {
120   const ambiguities = JSON.parse(event.data);
121
122   window.game.set_ambiguities(ambiguities);
123 });
124
125 events.addEventListener("player-judged", event => {
126   const player = JSON.parse(event.data);
127
128   window.game.set_player_judged(player);
129 });
130
131 events.addEventListener("player-judging", event => {
132   const player = JSON.parse(event.data);
133
134   window.game.set_player_judging(player);
135 });
136
137 events.addEventListener("vote-end-judging", event => {
138   const player = JSON.parse(event.data);
139
140   window.game.set_player_vote_end_judging(player);
141 });
142
143 events.addEventListener("unvote-end-judging", event => {
144   const player = JSON.parse(event.data);
145
146   window.game.set_player_unvote_end_judging(player);
147 });
148
149 events.addEventListener("scores", event => {
150   const scores = JSON.parse(event.data);
151
152   window.game.set_scores(scores);
153 });
154
155 /*********************************************************
156  * Game and supporting classes                           *
157  *********************************************************/
158
159 function copy_to_clipboard(id)
160 {
161   const tmp = document.createElement("input");
162   tmp.setAttribute("value", document.getElementById(id).innerHTML);
163   document.body.appendChild(tmp);
164   tmp.select();
165   document.execCommand("copy");
166   document.body.removeChild(tmp);
167 }
168
169 const GameInfo = React.memo(props => {
170   if (! props.id)
171     return null;
172
173   return (
174     <div className="game-info">
175       <span className="game-id">{props.id}</span>
176       {" "}
177       Share this link to invite friends:{" "}
178       <span id="game-share-url">{props.url}</span>
179       {" "}
180       <button
181         className="inline"
182         onClick={() => copy_to_clipboard('game-share-url')}
183       >Copy Link</button>
184     </div>
185   );
186 });
187
188 const PlayerInfo = React.memo(props => {
189   if (! props.player.id)
190     return null;
191
192   return (
193     <div className="player-info">
194       <span className="players-header">Players: </span>
195       {props.player.name}
196       {props.player.score > 0 ? ` (${props.player.score})` : ""}
197       {props.other_players.map(other => (
198         <span key={other.id}>
199           {", "}
200           {other.name}
201           {other.score > 0 ? ` (${other.score})` : ""}
202         </span>
203       ))}
204     </div>
205   );
206 });
207
208 function fetch_method_json(method, api = '', data = {}) {
209   const response = fetch(api, {
210     method: method,
211     headers: {
212       'Content-Type': 'application/json'
213     },
214     body: JSON.stringify(data)
215   });
216   return response;
217 }
218
219 function fetch_post_json(api = '', data = {}) {
220   return fetch_method_json('POST', api, data);
221 }
222
223 async function fetch_put_json(api = '', data = {}) {
224   return fetch_method_json('PUT', api, data);
225 }
226
227 class CategoryRequest extends React.PureComponent {
228   constructor(props) {
229     super(props);
230     this.category = React.createRef();
231
232     this.handle_change = this.handle_change.bind(this);
233     this.handle_submit = this.handle_submit.bind(this);
234   }
235
236   handle_change(event) {
237     const category_input = this.category.current;
238     const category = category_input.value;
239
240     const match = category.match(/[0-9]+/);
241     if (match) {
242       const num_items = parseInt(match[0], 10);
243       if (num_items <= MAX_PROMPT_ITEMS)
244         category_input.setCustomValidity("");
245     }
246   }
247
248   async handle_submit(event) {
249     const form = event.currentTarget;
250     const category_input = this.category.current;
251     const category = category_input.value;
252
253     /* Prevent the default page-changing form-submission behavior. */
254     event.preventDefault();
255
256     const match = category.match(/[0-9]+/);
257     if (match === null) {
258       category_input.setCustomValidity("Category must include a number");
259       form.reportValidity();
260       return;
261     }
262
263     const num_items = parseInt(match[0], 10);
264
265     if (num_items > MAX_PROMPT_ITEMS) {
266       category_input.setCustomValidity(`Maximum number of items is ${MAX_PROMPT_ITEMS}`);
267       form.reportValidity();
268       return;
269     }
270
271     const response = await fetch_post_json("prompts", {
272       items: num_items,
273       prompt: category
274     });
275
276     if (response.status === 200) {
277       const result = await response.json();
278       if (! result.valid) {
279         add_message("danger", result.message);
280         return;
281       }
282     } else {
283       add_message("danger", "An error occurred submitting your category");
284     }
285
286     form.reset();
287   }
288
289   render() {
290     return (
291       <div className="category-request">
292         <h2>Submit a Category</h2>
293         <p>
294           Suggest a category to play. Don't forget to include the
295           number of items for each person to submit.
296         </p>
297
298         <form onSubmit={this.handle_submit} >
299           <div className="form-field large">
300             <input
301               type="text"
302               id="category"
303               placeholder="6 things at the beach"
304               required
305               autoComplete="off"
306               onChange={this.handle_change}
307               ref={this.category}
308             />
309           </div>
310
311           <div className="form-field large">
312             <button type="submit">
313               Send
314             </button>
315           </div>
316
317         </form>
318       </div>
319     );
320   }
321 }
322
323 const PromptOptions = React.memo(props => {
324
325   if (props.prompts.length === 0)
326     return null;
327
328   return (
329     <div className="prompt-options">
330       <h2>Vote on Categories</h2>
331       <p>
332         Select any categories below that you'd like to play.
333         You can choose as many as you'd like.
334       </p>
335       {props.prompts.map(p => {
336         return (
337           <button
338             className="vote-button"
339             key={p.id}
340             onClick={() => fetch_post_json(`vote/${p.id}`) }
341           >
342             {p.prompt}
343             <div className="vote-choices">
344               {p.votes.map(v => {
345                 return (
346                   <div
347                     key={v}
348                     className="vote-choice"
349                   >
350                     {v}
351                   </div>
352                 );
353               })}
354             </div>
355           </button>
356         );
357       })}
358     </div>
359   );
360 });
361
362 const LetsPlay = React.memo(props => {
363
364   const quorum = Math.round((props.num_players + 1) / 2);
365   const max_votes = props.prompts.reduce(
366     (max_so_far, v) => Math.max(max_so_far, v.votes.length), 0);
367
368   if (max_votes < quorum)
369     return null;
370
371   const candidates = props.prompts.filter(p => p.votes.length >= quorum);
372   const index = Math.floor(Math.random() * candidates.length);
373   const winner = candidates[index];
374
375   return (
376     <div className="lets-play">
377       <h2>Let's Play</h2>
378       <p>
379         That should be enough voting. If you're not waiting for any
380         other players to join, then let's start.
381       </p>
382       <button
383         className="lets-play"
384         onClick={() => fetch_post_json(`start/${winner.id}`) }
385       >
386         Start Game
387       </button>
388     </div>
389   );
390 });
391
392 class Ambiguities extends React.PureComponent {
393
394   constructor(props) {
395     super(props);
396
397     const word_sets = props.words.map(word => {
398       const set = new Set();
399       set.add(word);
400       return set;
401     });
402
403     this.state = {
404       word_sets: word_sets,
405       selected: null
406     };
407
408     this.submitted = false;
409     this.judging_sent_recently = false;
410   }
411
412   async handle_submit() {
413
414     /* Don't submit a second time. */
415     if (this.submitted)
416       return;
417
418     const response = await fetch_post_json(
419       `judged/${this.props.prompt.id}`,{
420         word_groups: this.state.word_sets.map(set => Array.from(set))
421       }
422     );
423
424     if (response.status === 200) {
425       const result = await response.json();
426       if (! result.valid) {
427         add_message("danger", result.message);
428         return;
429       }
430     } else {
431       add_message("danger", "An error occurred submitting the results of your judging");
432       return;
433     }
434
435     this.submitted = true;
436   }
437
438   handle_click(word) {
439
440     /* Let the server know we are doing some judging, (but rate limit
441      * this so we don't send a "judging" notification more frquently
442      * than necessary.
443      */
444     if (! this.judging_sent_recently) {
445       fetch_post_json(`judging/${this.props.prompt.id}`);
446       this.judging_sent_recently = true;
447       setTimeout(() => { this.judging_sent_recently = false; }, 1000);
448     }
449
450     if (this.state.selected == word) {
451       /* Second click on same word removes the word from the group. */
452       const idx = this.state.word_sets.findIndex(s => s.has(word));
453       const set = this.state.word_sets[idx];
454       if (set.size === 1) {
455         /* When the word is already alone, there's nothing to do but
456          * to un-select it. */
457         this.setState({
458           selected: null
459         });
460         return;
461       }
462
463       const new_set = new Set([...set].filter(w => w !== word));
464       this.setState({
465         selected: null,
466         word_sets: [...this.state.word_sets.slice(0, idx),
467                     new_set,
468                     new Set().add(word),
469                     ...this.state.word_sets.slice(idx+1)]
470       });
471     } else if (this.state.selected) {
472       /* Click of a second word groups the two together. */
473       const idx1 = this.state.word_sets.findIndex(s => s.has(this.state.selected));
474       const idx2 = this.state.word_sets.findIndex(s => s.has(word));
475       const set1 = this.state.word_sets[idx1];
476       const set2 = this.state.word_sets[idx2];
477       const new_set = new Set([...set2, ...set1]);
478       if (idx1 < idx2) {
479         this.setState({
480           selected: null,
481           word_sets: [...this.state.word_sets.slice(0, idx1),
482                       ...this.state.word_sets.slice(idx1 + 1, idx2),
483                       new_set,
484                       ...this.state.word_sets.slice(idx2 + 1)]
485         });
486       } else {
487         this.setState({
488           selected: null,
489           word_sets: [...this.state.word_sets.slice(0, idx2),
490                       new_set,
491                       ...this.state.word_sets.slice(idx2 + 1, idx1),
492                       ...this.state.word_sets.slice(idx1 + 1)]
493         });
494       }
495     } else {
496       /* First click of a word selects it. */
497       this.setState({
498         selected: word
499       });
500     }
501   }
502
503   render() {
504     if (this.props.players_judged.has(this.props.player.name)) {
505       return (
506         <div className="please-wait">
507           <h2>Submission received</h2>
508           <p>
509             The following players have completed judging:
510             {[...this.props.players_judged].join(', ')}
511           </p>
512           <p>
513             Still waiting for the following players:
514           </p>
515           <ul>
516             {Object.keys(this.props.players_judging).map(player => {
517               return (
518                 <li
519                   key={player}
520                 >
521                   {player}
522                   {this.props.players_judging[player] ?
523                    <span className="typing"/> : null }
524                 </li>
525               );
526             })}
527           </ul>
528           <button
529             className="vote-button"
530             onClick={() => fetch_post_json(`end-judging/${this.props.prompt.id}`) }
531           >
532             Move On
533             <div className="vote-choices">
534               {[...this.props.votes].map(v => {
535                 return (
536                   <div
537                     key={v}
538                     className="vote-choice"
539                   >
540                     {v}
541                   </div>
542                 );
543               })}
544             </div>
545           </button>
546
547         </div>
548       );
549     }
550
551     const btn_class = "ambiguity-button";
552     const btn_selected_class = btn_class + " selected";
553
554     return (
555       <div className="ambiguities">
556         <h2>Judging Answers</h2>
557         <p>
558           Click on each pair of answers that should be scored as equivalent,
559           (and click any word twice to split it out from a group). Remember,
560           what goes around comes around, so it's best to be generous when
561           judging.
562         </p>
563         {this.state.word_sets.map(set => {
564           return (
565             <div
566               className="ambiguity-group"
567               key={Array.from(set)[0]}
568             >
569               {Array.from(set).map(word => {
570                 return (
571                   <button
572                     className={this.state.selected === word ?
573                                btn_selected_class : btn_class }
574                     key={word}
575                     onClick={() => this.handle_click(word)}
576                   >
577                     {word}
578                   </button>
579                 );
580               })}
581             </div>
582           );
583         })}
584         <p>
585           Click here when done judging:<br/>
586           <button
587             onClick={() => this.handle_submit()}
588           >
589             Send
590           </button>
591         </p>
592       </div>
593     );
594   }
595 }
596
597 class ActivePrompt extends React.PureComponent {
598
599   constructor(props) {
600     super(props);
601     const items = props.prompt.items;
602
603     this.submitted = false;
604
605     this.answers = [...Array(items)].map(() => React.createRef());
606     this.answering_sent_recently = false;
607
608     this.handle_submit = this.handle_submit.bind(this);
609     this.handle_change = this.handle_change.bind(this);
610   }
611
612   handle_change(event) {
613     /* We don't care (or even look) at what the player is typing at
614      * this point. We simply want to be informed that the player _is_
615      * typing so that we can tell the server (which will tell other
616      * players) that there is activity here.
617      */
618
619     /* Rate limit so that we don't send an "answering" notification
620      * more frequently than necessary.
621      */
622     if (! this.answering_sent_recently) {
623       fetch_post_json(`answering/${this.props.prompt.id}`);
624       this.answering_sent_recently = true;
625       setTimeout(() => { this.answering_sent_recently = false; }, 1000);
626     }
627   }
628
629   async handle_submit(event) {
630     const form = event.currentTarget;
631
632     /* Prevent the default page-changing form-submission behavior. */
633     event.preventDefault();
634
635     /* And don't submit a second time. */
636     if (this.submitted)
637       return;
638
639     const response = await fetch_post_json(`answer/${this.props.prompt.id}`, {
640       answers: this.answers.map(r => r.current.value)
641     });
642     if (response.status === 200) {
643       const result = await response.json();
644       if (! result.valid) {
645         add_message("danger", result.message);
646         return;
647       }
648     } else {
649       add_message("danger", "An error occurred submitting your answers");
650       return;
651     }
652
653     /* Everything worked. Server is happy with our answers. */
654     form.reset();
655     this.submitted = true;
656   }
657
658   render() {
659     if (this.props.players_answered.has(this.props.player.name)) {
660       return (
661         <div className="please-wait">
662           <h2>Submission received</h2>
663           <p>
664             The following players have submitted their answers:
665             {[...this.props.players_answered].join(', ')}
666           </p>
667           <p>
668           Still waiting for the following players:
669           </p>
670           <ul>
671             {Object.keys(this.props.players_answering).map(player => {
672               return (
673                 <li
674                   key={player}
675                 >
676                   {player}
677                   {this.props.players_answering[player] ?
678                    <span className="typing"/> : null }
679                 </li>
680               );
681             })}
682           </ul>
683           <button
684             className="vote-button"
685             onClick={() => fetch_post_json(`end-answers/${this.props.prompt.id}`) }
686           >
687             Move On
688             <div className="vote-choices">
689               {[...this.props.votes].map(v => {
690                 return (
691                   <div
692                     key={v}
693                     className="vote-choice"
694                   >
695                     {v}
696                   </div>
697                 );
698               })}
699             </div>
700           </button>
701
702         </div>
703       );
704     }
705
706     return (
707       <div className="active-prompt">
708         <h2>The Game of Empathy</h2>
709         <p>
710           Remember, you're trying to match your answers with
711           what the other players submit.
712           Give {this.props.prompt.items} answers for the following prompt:
713         </p>
714         <h2>{this.props.prompt.prompt}</h2>
715         <form onSubmit={this.handle_submit}>
716           {[...Array(this.props.prompt.items)].map((whocares,i) => {
717             return (
718               <div
719                 key={i}
720                 className="form-field large">
721                 <input
722                   type="text"
723                   name={`answer_${i}`}
724                   required
725                   autoComplete="off"
726                   onChange={this.handle_change}
727                   ref={this.answers[i]}
728                 />
729               </div>
730             );
731           })}
732
733           <div
734             key="submit-button"
735             className="form-field large">
736             <button type="submit">
737               Send
738             </button>
739           </div>
740
741         </form>
742       </div>
743     );
744   }
745 }
746
747 class Game extends React.PureComponent {
748   constructor(props) {
749     super(props);
750     this.state = {
751       game_info: {},
752       player_info: {},
753       other_players: [],
754       prompts: [],
755       active_prompt: null,
756       players_answered: new Set(),
757       players_answering: {},
758       end_answers_votes: new Set(),
759       ambiguities: null,
760       players_judged: new Set(),
761       players_judging: {},
762       end_judging_votes: new Set(),
763       scores: null
764     };
765   }
766
767   set_game_info(info) {
768     this.setState({
769       game_info: info
770     });
771   }
772
773   set_player_info(info) {
774     this.setState({
775       player_info: info
776     });
777   }
778
779   set_other_player_info(info) {
780     const other_players_copy = [...this.state.other_players];
781     const idx = other_players_copy.findIndex(o => o.id === info.id);
782     if (idx >= 0) {
783       other_players_copy[idx] = info;
784     } else {
785       other_players_copy.push(info);
786     }
787     this.setState({
788       other_players: other_players_copy
789     });
790   }
791
792   reset_game_state() {
793     this.setState({
794       prompts: [],
795       active_prompt: null,
796       players_answered: new Set(),
797       players_answering: {},
798       end_answers_votes: new Set(),
799       ambiguities: null,
800       players_judged: new Set(),
801       players_judging: {},
802       end_judging_votes: new Set(),
803       scores: null
804     });
805   }
806
807   set_prompts(prompts) {
808     this.setState({
809       prompts: prompts
810     });
811   }
812
813   add_or_update_prompt(prompt) {
814     const prompts_copy = [...this.state.prompts];
815     const idx = prompts_copy.findIndex(p => p.id === prompt.id);
816     if (idx >= 0) {
817       prompts_copy[idx] = prompt;
818     } else {
819       prompts_copy.push(prompt);
820     }
821     this.setState({
822       prompts: prompts_copy
823     });
824   }
825
826   set_active_prompt(prompt) {
827     this.setState({
828       active_prompt: prompt
829     });
830   }
831
832   set_players_answered(players) {
833     this.setState({
834       players_answered: new Set(players)
835     });
836   }
837
838   set_player_answered(player) {
839     const new_players_answering = {...this.state.players_answering};
840     delete new_players_answering[player];
841
842     this.setState({
843       players_answered: new Set([...this.state.players_answered, player]),
844       players_answering: new_players_answering
845     });
846   }
847
848   set_players_answering(players) {
849     const players_answering = {};
850     for (let player of players) {
851       players_answering[player] = {active: false};
852     }
853     this.setState({
854       players_answering: players_answering
855     });
856   }
857
858   set_player_answering(player) {
859     this.setState({
860       players_answering: {
861         ...this.state.players_answering,
862         [player]: {active: true}
863       }
864     });
865   }
866
867   set_end_answers(players) {
868     this.setState({
869       end_answers_votes: new Set(players)
870     });
871   }
872
873   set_player_vote_end_answers(player) {
874     this.setState({
875       end_answers_votes: new Set([...this.state.end_answers_votes, player])
876     });
877   }
878
879   set_player_unvote_end_answers(player) {
880     this.setState({
881       end_answers_votes: new Set([...this.state.end_answers_votes].filter(p => p !== player))
882     });
883   }
884
885   set_ambiguities(ambiguities) {
886     this.setState({
887       ambiguities: ambiguities
888     });
889   }
890
891   set_players_judged(players) {
892     this.setState({
893       players_judged: new Set(players)
894     });
895   }
896
897   set_player_judged(player) {
898     const new_players_judging = {...this.state.players_judging};
899     delete new_players_judging[player];
900
901     this.setState({
902       players_judged: new Set([...this.state.players_judged, player]),
903       players_judging: new_players_judging
904     });
905   }
906
907   set_players_judging(players) {
908     const players_judging = {};
909     for (let player of players) {
910       players_judging[player] = {active: false};
911     }
912     this.setState({
913       players_judging: players_judging
914     });
915   }
916
917   set_player_judging(player) {
918     this.setState({
919       players_judging: {
920         ...this.state.players_judging,
921         [player]: {active: true}
922       }
923     });
924   }
925
926   set_end_judging(players) {
927     this.setState({
928       end_judging_votes: new Set(players)
929     });
930   }
931
932   set_player_vote_end_judging(player) {
933     this.setState({
934       end_judging_votes: new Set([...this.state.end_judging_votes, player])
935     });
936   }
937
938   set_player_unvote_end_judging(player) {
939     this.setState({
940       end_judging_votes: new Set([...this.state.end_judging_votes].filter(p => p !== player))
941     });
942   }
943
944   set_scores(scores) {
945     this.setState({
946       scores: scores
947     });
948   }
949
950   render() {
951     const state = this.state;
952     const players_total = 1 + state.other_players.length;
953
954     if (state.scores) {
955       return (
956         <div className="scores">
957           <h2>Scores</h2>
958           <ul>
959             {state.scores.scores.map(score => {
960               return (
961                 <li key={score.player}>
962                   {score.player}: {score.score}
963                 </li>
964               );
965             })}
966           </ul>
967           <h2>Words submitted</h2>
968           <ul>
969             {state.scores.words.map(word => {
970               return (
971                 <li key={word.word}>
972                   {`${word.word}: ${word.players.join(', ')}`}
973                 </li>
974               );
975             })}
976           </ul>
977           <button
978             className="new-game"
979             onClick={() => fetch_post_json('reset') }
980           >
981             New Game
982           </button>
983         </div>
984       );
985     }
986
987     if (state.ambiguities){
988       return <Ambiguities
989                prompt={state.active_prompt}
990                words={state.ambiguities}
991                player={state.player_info}
992                players_judged={state.players_judged}
993                players_judging={state.players_judging}
994                votes={state.end_judging_votes}
995              />;
996     }
997
998     if (state.active_prompt) {
999       return <ActivePrompt
1000                prompt={state.active_prompt}
1001                player={state.player_info}
1002                players_answered={state.players_answered}
1003                players_answering={state.players_answering}
1004                votes={state.end_answers_votes}
1005              />;
1006     }
1007
1008     return [
1009       <GameInfo
1010         key="game-info"
1011         id={state.game_info.id}
1012         url={state.game_info.url}
1013       />,
1014       <PlayerInfo
1015         key="player-info"
1016         game={this}
1017         player={state.player_info}
1018         other_players={state.other_players}
1019       />,
1020       <p key="spacer"></p>,
1021       <CategoryRequest
1022         key="category-request"
1023       />,
1024       <PromptOptions
1025         key="prompts"
1026         prompts={state.prompts}
1027       />,
1028       <LetsPlay
1029         key="lets-play"
1030         num_players={1+state.other_players.length}
1031         prompts={state.prompts}
1032       />
1033     ];
1034   }
1035 }
1036
1037 ReactDOM.render(<Game
1038                   ref={(me) => window.game = me}
1039                 />, document.getElementById("empathy"));