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 3 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
17 changes: 14 additions & 3 deletions src/QuestionViewer/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* global fetchWithAuth */

import Component from 'inferno-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 &&
<a class="button float-left" href={`/question/${qno-1}`}>
Prev
</a>
}
{
qno!==5 &&
<a class="button float-right" href={`/question/${qno+1}`}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use Link component instead of a like we do in navbar

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Difference is this will not cause the page to reload

Next
</a>
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be done much more neatly.

<div>
 {qno !== 1 && .....prev....}
 {qno !== 5 && .....next....}
</div>

</div>
)
}
Expand Down