Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Display scoreboard (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
troublemagnet authored and meghprkh committed Sep 29, 2017
1 parent 1fed065 commit 9f2c107
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Navbar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export default () => (
:
<ul className="navigation-list float-right">
<li className="navigation-item navigation-link"> Hello {window.email} </li>
<li className="navigation-item"><Link to='/scoreboard' className="navigation-link">Scoreboard</Link></li>
<li className="navigation-item"><Link to='/logout' className="navigation-link">Logout</Link></li>
</ul>
}
Expand Down
34 changes: 34 additions & 0 deletions src/Scoreboard/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import Component from 'inferno-component';
class Scoreboard extends Component {
state = {
scores: [],
error: '',
}
async componentDidMount() {
var res = await window.fetchWithAuth('/scoreboard');
res = await res.json();
if (!res.error) this.setState({ scores: res})
else this.setState({ error: res.error})
}
render() {
const { scores, error } = this.state
return (
<div>
<table>
<th>
<td> Name </td>
<td> Score </td>
</th>
{scores.map(user => (
<tr>
<td> {user.name} </td>
<td> {user.score} </td>
</tr>))}
</table>
{error && <div className="error">ERROR: {error}</div>}
</div>
)
}
}

export default Scoreboard;
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Login from './Login';
import Logout from './Logout';
import QuestionsList from './QuestionsList';
import QuestionViewer from './QuestionViewer';
import Scoreboard from './Scoreboard';

const browserHistory = createBrowserHistory();
window.browserHistory = browserHistory;
Expand All @@ -23,6 +24,7 @@ const routes = (
<IndexRoute component={QuestionsList}/>
<Route path="/question/:qno" component={QuestionViewer} />
<Route path="/login" component={Login} />
<Route path="/scoreboard" component={Scoreboard} />
<Route path="/logout" component={Logout} />
</Route>
</Router>
Expand Down

0 comments on commit 9f2c107

Please sign in to comment.