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

Issue 1 #6

Merged
merged 4 commits into from
Sep 26, 2017
Merged
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
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