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

Scoreboard displayed. #13

Merged
merged 3 commits into from
Sep 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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