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

Issue 4 #11

Closed
wants to merge 5 commits into from
Closed
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
12 changes: 8 additions & 4 deletions src/QuestionViewer/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Link } from 'inferno-router';
import linkState from 'linkstate';
import Component from 'inferno-component';

var Remarkable = require('remarkable');
var md = new Remarkable({
html: true,
Expand All @@ -26,10 +27,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
checkAnswer = e => {
e.preventDefault();
const answer = e.target[0].value
const qno = this.props.params.qno
window.alert(answer) //answer given by user
window.fetchWithAuth(`/questions/${qno}/answer`,{'body': {'answer':answer}, 'method' : 'POST' });
window.alert(qno) // question num
}

render() {
Expand Down
4 changes: 3 additions & 1 deletion src/fetchWithAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ window.fetchWithAuth = (url, options = {}) => {
body,
headers: {
...options.headers,
email: window.email
email: window.email,
'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8',

}
})
}