Merge pull request #12 from SundownDEV/devFront

Front integration
pull/16/head
Rémi Doreau 2018-06-05 18:20:25 +02:00 committed by GitHub
commit 7fe68ec2ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 14 deletions

View File

@ -8,7 +8,7 @@ class App extends Component {
super(props); super(props);
this.state = { this.state = {
currentResponses: [], currentResponses: [],
currentQuestion: "zfz", currentQuestion: "",
pastQuestion: null, pastQuestion: null,
pastResponse: null, pastResponse: null,
score: 0, score: 0,
@ -21,7 +21,7 @@ class App extends Component {
_handleClick(element) { _handleClick(element) {
this.setState({ this.setState({
pastQuestion: element.question , pastQuestion: this.state.currentQuestion ,
pastResponse: element.text, pastResponse: element.text,
score: this.state.score+1 score: this.state.score+1
}); });
@ -33,38 +33,38 @@ class App extends Component {
axios.get(url) axios.get(url)
.then(((data) => { .then(((data) => {
this.setState({ this.setState({
currentQuestion: data.text currentQuestion: data.data.text
}) })
})) }))
.catch(error => console.log(error)); .catch(error => console.log(error));
} }
fetchResponses(id) { fetchResponses(url) {
axios.get('http://localhost:8000/questions/'+ id +'responses') axios.get(url)
.then(((data) => { .then(((data) => {
this.setState({ this.setState({
currentResponses : data currentResponses : data.data
}) })
})) }))
} }
componentWillMount(){ componentWillMount(){
if(this.state.start) { if(this.state.start === true) {
this.fetchQuestion("http://localhost:8000/questions/0"); this.fetchQuestion(this.state.baseRoute+"/questions/1");
this.fetchResponses(0); this.fetchResponses(this.state.baseRoute+"/questions/1/responses");
this.setState ({ this.setState ({
start: null start: false
}) })
} }
} }
render() { render() {
let currentOptions = this.state.currentResponses.map(((element, index) => ( let currentOptions = this.state.currentResponses.map((element, index) => (
<p key={index}><a class="btn btn-default btn-lg btn-block text-left" onClick={this._handleClick.bind(this, element)}>{element.text}</a></p> <p key={index}><a className="btn btn-default btn-lg btn-block text-left" onClick={this._handleClick.bind(this, element)}>{element.text}</a></p>
))); ));
let header = ( let header = (
<div class="jumbotron"> <div className="jumbotron">
<h3>{this.state.pastQuestion}<br/> <h3>{this.state.pastQuestion}<br/>
<small> {this.state.pastResponse}</small></h3> <small> {this.state.pastResponse}</small></h3>
</div> </div>