Previously we were using a component state Boolean "submitted" for
this information, but that's fundamentally broken since if the client
reloads the page that state is lost, resulting in the user being
presented with the form as to submit a second time (which is not
allowed by the game).
So, now the rendering looks to see whether the current player's name
is in the list of submitted players, and if so, it does not display
the form. This is exactly what we want.
this.state = {
word_sets: word_sets,
this.state = {
word_sets: word_sets,
+ this.submitted = false;
this.judging_sent_recently = false;
}
async handle_submit() {
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))
const response = await fetch_post_json(
`judged/${this.props.prompt.id}`,{
word_groups: this.state.word_sets.map(set => Array.from(set))
- this.setState({
- submitted: true
- });
- if (this.state.submitted)
+ if (this.props.players_judged.has(this.props.player.name)) {
return (
<div className="please-wait">
<h2>Submission received</h2>
return (
<div className="please-wait">
<h2>Submission received</h2>
const btn_class = "ambiguity-button";
const btn_selected_class = btn_class + " selected";
const btn_class = "ambiguity-button";
const btn_selected_class = btn_class + " selected";
super(props);
const items = props.prompt.items;
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;
this.answers = [...Array(items)].map(() => React.createRef());
this.answering_sent_recently = false;
/* Prevent the default page-changing form-submission behavior. */
event.preventDefault();
/* 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)
});
const response = await fetch_post_json(`answer/${this.props.prompt.id}`, {
answers: this.answers.map(r => r.current.value)
});
/* Everything worked. Server is happy with our answers. */
form.reset();
/* Everything worked. Server is happy with our answers. */
form.reset();
- this.setState({
- submitted: true
- });
- if (this.state.submitted)
+ if (this.props.players_answered.has(this.props.player.name)) {
return (
<div className="please-wait">
<h2>Submission received</h2>
return (
<div className="please-wait">
<h2>Submission received</h2>
return (
<div className="active-prompt">
return (
<div className="active-prompt">
return <Ambiguities
prompt={state.active_prompt}
words={state.ambiguities}
return <Ambiguities
prompt={state.active_prompt}
words={state.ambiguities}
+ player={state.player_info}
players_judged={state.players_judged}
players_judging={state.players_judging}
votes={state.end_judging_votes}
players_judged={state.players_judged}
players_judging={state.players_judging}
votes={state.end_judging_votes}
if (state.active_prompt) {
return <ActivePrompt
prompt={state.active_prompt}
if (state.active_prompt) {
return <ActivePrompt
prompt={state.active_prompt}
+ player={state.player_info}
players_answered={state.players_answered}
players_answering={state.players_answering}
votes={state.end_answers_votes}
players_answered={state.players_answered}
players_answering={state.players_answering}
votes={state.end_answers_votes}