);
});
@@ -225,7 +318,6 @@ class CategoryRequest extends React.PureComponent {
if (response.status === 200) {
const result = await response.json();
- console.log(result);
if (! result.valid) {
add_message("danger", result.message);
return;
@@ -312,10 +404,6 @@ const PromptOptions = React.memo(props => {
const LetsPlay = React.memo(props => {
- function handle_click(prompt_id) {
- fetch_post_json
- }
-
const quorum = Math.round((props.num_players + 1) / 2);
const max_votes = props.prompts.reduce(
(max_so_far, v) => Math.max(max_so_far, v.votes.length), 0);
@@ -357,14 +445,21 @@ class Ambiguities extends React.PureComponent {
this.state = {
word_sets: word_sets,
- submitted: false,
selected: null
};
+
+ this.submitted = false;
+ this.judging_sent_recently = false;
}
async handle_submit() {
+
+ /* Don't submit a second time. */
+ if (this.submitted)
+ return;
+
const response = await fetch_post_json(
- `judging/${this.props.prompt.id}`,{
+ `judged/${this.props.prompt.id}`,{
word_groups: this.state.word_sets.map(set => Array.from(set))
}
);
@@ -376,22 +471,38 @@ class Ambiguities extends React.PureComponent {
return;
}
} else {
- add_message("danger", "An error occurred submitting your answers");
+ add_message("danger", "An error occurred submitting the results of your judging");
return;
}
- this.setState({
- submitted: true
- });
+ this.submitted = true;
}
handle_click(word) {
+
+ /* Let the server know we are doing some judging, (but rate limit
+ * this so we don't send a "judging" notification more frquently
+ * than necessary.
+ */
+ if (! this.judging_sent_recently) {
+ fetch_post_json(`judging/${this.props.prompt.id}`);
+ this.judging_sent_recently = true;
+ setTimeout(() => { this.judging_sent_recently = false; }, 1000);
+ }
+
if (this.state.selected == word) {
/* Second click on same word removes the word from the group. */
const idx = this.state.word_sets.findIndex(s => s.has(word));
const set = this.state.word_sets[idx];
- if (set.size === 1)
+ if (set.size === 1) {
+ /* When the word is already alone, there's nothing to do but
+ * to un-select it. */
+ this.setState({
+ selected: null
+ });
return;
+ }
+
const new_set = new Set([...set].filter(w => w !== word));
this.setState({
selected: null,
@@ -433,16 +544,60 @@ class Ambiguities extends React.PureComponent {
}
render() {
- if (this.state.submitted)
+ let move_on_button = null;
+
+ if (this.props.idle) {
+ move_on_button = (
+
+ );
+ }
+
+ if (this.props.players_judged.has(this.props.player.name)) {
return (
-
{this.props.players_judged}/
- {this.props.players_total} players have responded
+
Submission received
- Please wait for the rest of the players to complete judging.
+ The following players have completed judging:{' '}
+ {[...this.props.players_judged].join(', ')}
);
+ }
const btn_class = "ambiguity-button";
const btn_selected_class = btn_class + " selected";
@@ -456,6 +611,7 @@ class Ambiguities extends React.PureComponent {
what goes around comes around, so it's best to be generous when
judging.
+
{this.props.prompt.prompt}
{this.state.word_sets.map(set => {
return (
React.createRef());
+ this.answering_sent_recently = false;
+
this.handle_submit = this.handle_submit.bind(this);
+ this.handle_change = this.handle_change.bind(this);
+ }
+
+ handle_change(event) {
+ /* We don't care (or even look) at what the player is typing at
+ * this point. We simply want to be informed that the player _is_
+ * typing so that we can tell the server (which will tell other
+ * players) that there is activity here.
+ */
+
+ /* Rate limit so that we don't send an "answering" notification
+ * more frequently than necessary.
+ */
+ if (! this.answering_sent_recently) {
+ fetch_post_json(`answering/${this.props.prompt.id}`);
+ this.answering_sent_recently = true;
+ setTimeout(() => { this.answering_sent_recently = false; }, 1000);
+ }
}
async handle_submit(event) {
@@ -510,6 +684,10 @@ class ActivePrompt extends React.PureComponent {
/* Prevent the default page-changing form-submission behavior. */
event.preventDefault();
+ /* And don't submit a second time. */
+ if (this.submitted)
+ return;
+
const response = await fetch_post_json(`answer/${this.props.prompt.id}`, {
answers: this.answers.map(r => r.current.value)
});
@@ -526,22 +704,63 @@ class ActivePrompt extends React.PureComponent {
/* Everything worked. Server is happy with our answers. */
form.reset();
- this.setState({
- submitted: true
- });
+ this.submitted = true;
}
render() {
- if (this.state.submitted)
+ let move_on_button = null;
+ if (this.props.idle) {
+ move_on_button =(
+
+ );
+ }
+
+ if (this.props.players_answered.has(this.props.player.name)) {
return (
-
{this.props.players_answered}/
- {this.props.players_total} players have responded
+
Submission received
+
+ The following players have submitted their answers:{' '}
+ {[...this.props.players_answered].join(', ')}
+
- Please wait for the rest of the players to submit their answers.
+ Still waiting for the following players:
@@ -549,7 +768,8 @@ class ActivePrompt extends React.PureComponent {
Remember, you're trying to match your answers with
what the other players submit.
- Give {this.props.prompt.items} answers for the following prompt:
+ Give {this.props.prompt.items} answer
+ {this.props.prompt.items > 1 ? 's' : ''} for the following prompt: