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

Commit

Permalink
Add answer questionviewer stub
Browse files Browse the repository at this point in the history
  • Loading branch information
meghprkh committed Sep 27, 2017
1 parent 941e845 commit dcb7e6d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"inferno-component": "^3.9.0",
"inferno-router": "^3.9.0",
"inferno-scripts": "4.2.0",
"linkstate": "^1.1.0",
"milligram": "^1.3.0"
},
"proxy": "http://localhost:3000",
Expand Down
14 changes: 13 additions & 1 deletion src/QuestionViewer/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Link } from 'inferno-router';
import linkState from 'linkstate';
import Component from 'inferno-component';

class QuestionViewer extends Component {
Expand All @@ -19,8 +20,13 @@ class QuestionViewer extends Component {
if (!res.error) this.setState({ question: res, loading: false })
else this.setState({ error: res.error, loading: false })
}
async checkAnswer() {
// XXX: Need to fill in this stub
// Read fetch documentation on how to send post request and
// display output in window.alert
}
render() {
const { loading, question, error } = this.state
const { loading, question, error, answer } = this.state
const qno = parseInt(this.props.params.qno,10)
return (
<div>
Expand All @@ -30,6 +36,12 @@ class QuestionViewer extends Component {
<p>
{question.body}
</p>
<form onSubmit={this.checkAnswer}>
<label for='answer'>Answer</label>
<input type='text' name='answer' value={answer} onInput={linkState(this, 'answer')} />
<button class='button-primary float-right'>Check</button>
</form>
<div class="clearfix" />
{
qno!==1 &&
<Link className="button float-left" to={`/question/${qno-1}`}>
Expand Down
4 changes: 4 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3934,6 +3934,10 @@ levn@^0.3.0, levn@~0.3.0:
prelude-ls "~1.1.2"
type-check "~0.3.2"

linkstate@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/linkstate/-/linkstate-1.1.0.tgz#c84643731c7fcbf2efdee70d23c04e145f84a5a3"

load-json-file@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-1.1.0.tgz#956905708d58b4bab4c2261b04f59f31c99374c0"
Expand Down

0 comments on commit dcb7e6d

Please sign in to comment.