X-Git-Url: https://git.cworth.org/git?p=lmno.games;a=blobdiff_plain;f=empathy%2Fempathy.jsx;h=566ad105c5e3cdb3727ffe504d74ca52e9c0efc4;hp=1a9ad80ceb7298d0c7e341ccddce680b1a80870d;hb=04b3139e734606e5281f7a784c3a04ce1b02cc4d;hpb=3dce1ecbdc99e7afbcb0338e585b4e587e0c6cd2 diff --git a/empathy/empathy.jsx b/empathy/empathy.jsx index 1a9ad80..566ad10 100644 --- a/empathy/empathy.jsx +++ b/empathy/empathy.jsx @@ -63,9 +63,21 @@ events.addEventListener("game-state", event => { window.game.set_active_prompt(state.active_prompt); - window.game.set_scores(state.scores); + window.game.set_players_answered(state.players_answered); + + window.game.set_players_answering(state.players_answering); + + window.game.set_end_answers(state.end_answers); window.game.set_ambiguities(state.ambiguities); + + window.game.set_players_judged(state.players_judged); + + window.game.set_players_judging(state.players_judging); + + window.game.set_end_judging(state.end_judging); + + window.game.set_scores(state.scores); }); events.addEventListener("prompt", event => { @@ -349,10 +361,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); @@ -397,11 +405,13 @@ class Ambiguities extends React.PureComponent { submitted: false, selected: null }; + + this.judging_sent_recently = false; } async handle_submit() { 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)) } ); @@ -413,7 +423,7 @@ 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; } @@ -423,12 +433,30 @@ class Ambiguities extends React.PureComponent { } 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, @@ -482,7 +510,7 @@ class Ambiguities extends React.PureComponent { Still waiting for the following players: