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

Commit

Permalink
Add Previous and Next Buttons to QuestionViewer (Fix #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kunalgarg2100 authored and meghprkh committed Sep 26, 2017
1 parent b4a6f21 commit d90c179
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/QuestionViewer/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* global fetchWithAuth */

import { Link } from 'inferno-router';
import Component from 'inferno-component';

class QuestionViewer extends Component {
Expand All @@ -10,13 +9,14 @@ class QuestionViewer extends Component {
}
async componentDidMount() {
const { qno } = this.props.params;
var res = await fetchWithAuth(`/questions/${qno}`);
var res = await window.fetchWithAuth(`/questions/${qno}`);
res = await res.json();
if (!res.error) this.setState({ question: res, loading: false })
else this.setState({ error: res.error, loading: false })
}
render() {
const { loading, question, error } = this.state
const qno = parseInt(this.props.params.qno,10)
return (
<div>
{loading && <div>Loading...</div>}
Expand All @@ -25,7 +25,18 @@ class QuestionViewer extends Component {
<p>
{question.body}
</p>
{/* XXX: Need to add previous and next buttons here. Use the Link component from 'inferno-router' */}
{
qno!==1 &&
<Link className="button float-left" to={`/question/${qno-1}`}>
Prev
</Link>
}
{
qno!==5 &&
<Link className="button float-right" to={`/question/${qno+1}`}>
Next
</Link>
}
</div>
)
}
Expand Down

0 comments on commit d90c179

Please sign in to comment.