X-Git-Url: https://git.cworth.org/git?p=lmno.games;a=blobdiff_plain;f=empathy%2Fempathy.jsx;h=80069426d941666e2a812434bef72d2663995bbf;hp=566ad105c5e3cdb3727ffe504d74ca52e9c0efc4;hb=fbd247880d7fa0d04aecb61c8960876a3c7a6033;hpb=04b3139e734606e5281f7a784c3a04ce1b02cc4d diff --git a/empathy/empathy.jsx b/empathy/empathy.jsx index 566ad10..8006942 100644 --- a/empathy/empathy.jsx +++ b/empathy/empathy.jsx @@ -402,14 +402,19 @@ 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( `judged/${this.props.prompt.id}`,{ word_groups: this.state.word_sets.map(set => Array.from(set)) @@ -427,9 +432,7 @@ class Ambiguities extends React.PureComponent { return; } - this.setState({ - submitted: true - }); + this.submitted = true; } handle_click(word) { @@ -498,7 +501,7 @@ class Ambiguities extends React.PureComponent { } render() { - if (this.state.submitted) + if (this.props.players_judged.has(this.props.player.name)) { return (

Submission received

@@ -543,6 +546,7 @@ class Ambiguities extends React.PureComponent {
); + } const btn_class = "ambiguity-button"; const btn_selected_class = btn_class + " selected"; @@ -596,9 +600,7 @@ class ActivePrompt extends React.PureComponent { super(props); const items = props.prompt.items; - this.state = { - submitted: false - }; + this.submitted = false; this.answers = [...Array(items)].map(() => React.createRef()); this.answering_sent_recently = false; @@ -630,6 +632,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) }); @@ -646,13 +652,11 @@ 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) + if (this.props.players_answered.has(this.props.player.name)) { return (

Submission received

@@ -697,6 +701,7 @@ class ActivePrompt extends React.PureComponent {
); + } return (
@@ -983,6 +988,7 @@ class Game extends React.PureComponent { return