Skip to content

Commit

Permalink
😊 Updated the board for the answers.
Browse files Browse the repository at this point in the history
  • Loading branch information
CaptainOfFlyingDutchman committed Oct 23, 2016
1 parent cd0bf7a commit cc047fb
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 6 deletions.
4 changes: 3 additions & 1 deletion app-server.js
Expand Up @@ -49,7 +49,8 @@ io.on('connection', (client) => {
speaker: speaker,
audience: audience,
questions: questions,
currentQuestion: currentQuestion
currentQuestion: currentQuestion,
results: results
});

connections.push(client);
Expand Down Expand Up @@ -87,6 +88,7 @@ io.on('connection', (client) => {

client.on('answer', (payload) => {
results[payload.choice]++;
io.emit('results', results);
console.log('Answer: "%s" - %j', payload.choice, results);
});

Expand Down
7 changes: 6 additions & 1 deletion components/App.js
Expand Up @@ -14,7 +14,8 @@ export default class App extends Component {
audience: [],
speaker: {}, /* On every socket it's displayed who is the speaker */
questions: [],
currentQuestion: false
currentQuestion: false,
results: {}
};
this.emit = this.emit.bind(this);
this.udpateState = this.udpateState.bind(this);
Expand Down Expand Up @@ -63,6 +64,10 @@ export default class App extends Component {
this.setState({ currentQuestion: question });
});

this.socket.on('results', (results) => {
this.setState({ results: results });
});

this.socket.on('end', this.udpateState);

this.socket.on('disconnect', () => {
Expand Down
32 changes: 28 additions & 4 deletions components/Board.js
@@ -1,9 +1,33 @@
import React, { Component } from 'react';
import React, { Component, PropTypes } from 'react';

export default class Board extends Component {
import Display from './parts/Display';

class Board extends Component {
render() {
return (
<h1>Board {this.props.title}</h1>
<div id="scoreboard">
<Display if={this.props.status === 'connected' &&
this.props.currentQuestion}>
<h3>{this.props.currentQuestion.q}</h3>
<p>{JSON.stringify(this.props.results)}</p>
</Display>

<Display if={this.props.status === 'connected' &&
!this.props.currentQuestion}>
<h3>Awaiting a question...</h3>
</Display>

</div>
);
}
};
}

Board.propTypes = {
status: PropTypes.string,
currentQuestion: PropTypes.oneOfType([
PropTypes.object.isRequired,
PropTypes.bool.isRequired
])
};

export default Board;
1 change: 1 addition & 0 deletions components/parts/Join.js
Expand Up @@ -23,6 +23,7 @@ class Join extends Component {
<button className="btn btn-primary">Join</button>

<Link to="/speaker">Join as speaker</Link>
<Link to="/board">Go to the Board</Link>
</form>
);
}
Expand Down

0 comments on commit cc047fb

Please sign in to comment.