events.addEventListener("game-state", event => {
const state = JSON.parse(event.data);
- for (let prompt of state.prompts) {
- window.game.add_or_update_prompt(prompt);
- }
+ window.game.set_prompts(state.prompts);
window.game.set_active_prompt(state.active_prompt);
<div className="player-info">
<span className="players-header">Players: </span>
{props.player.name}
+ {props.player.score > 0 ? ` (${props.player.score})` : ""}
{props.other_players.map(other => (
<span key={other.id}>
{", "}
{other.name}
+ {other.score > 0 ? ` (${other.score})` : ""}
</span>
))}
</div>
const response = await fetch_post_json(`answer/${this.props.prompt.id}`, {
answers: this.answers.map(r => r.current.value)
});
- if (response.status == 200) {
+ if (response.status === 200) {
const result = await response.json();
if (! result.valid) {
add_message("danger", result.message);
</p>
<h2>{this.props.prompt.prompt}</h2>
<form onSubmit={this.handle_submit}>
- {Array(this.props.prompt.items).fill(null).map((whocares,i) => {
+ {[...Array(this.props.prompt.items)].map((whocares,i) => {
return (
<div
key={i}
});
}
+ set_prompts(prompts) {
+ this.setState({
+ prompts: prompts
+ });
+ }
+
add_or_update_prompt(prompt) {
const prompts_copy = [...this.state.prompts];
const idx = prompts_copy.findIndex(p => p.id === prompt.id);