generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Question's View Need to improve logic
- Loading branch information
Showing
4 changed files
with
52 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,4 +21,6 @@ class Question{ | |
return this.answers; | ||
} | ||
|
||
} | ||
} | ||
|
||
export default Question; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,27 @@ | ||
import Question from './Question'; | ||
class QuestionGenerator{ | ||
|
||
constructor(){ | ||
this.apiUrl = "http://localhost:8090/test"; | ||
this.questions = []; | ||
|
||
} | ||
|
||
generateQuestions(){ | ||
//Deberíamos recoger el json | ||
fetch(this.apiUrl) | ||
.then(response => response.json()) // Convertir la respuesta a JSON | ||
.then(receivedQuestions => { // La respuesta convertida a JSON se pasa como argumento | ||
.then(response => response.json()) | ||
.then(receivedQuestions => { | ||
let i = 0; | ||
var questions = []; | ||
for(const question in receivedQuestions){//To have a condition, no legth or size | ||
this.questions[i] = new Question(receivedQuestions[i]); | ||
questions[i] = new Question(receivedQuestions[i]); | ||
i += 1; | ||
} | ||
return questions; | ||
}); | ||
} | ||
|
||
} | ||
|
||
var q = new QuestionGenerator(); | ||
q.generateQuestions(); | ||
export default QuestionGenerator; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import Question from './Question'; | ||
import QuestionGenerator from './QuestionGenerator'; | ||
import { useState } from 'react'; | ||
|
||
const questionGenerator = new QuestionGenerator(); | ||
var questions = questionGenerator.generateQuestions(); | ||
|
||
function QuestionView(){ | ||
const [numQuestion, setnumQuestion] = useState(0); | ||
|
||
function handleClick(){ | ||
setnumQuestion(numQuestion + 1); | ||
} | ||
return (<div> | ||
{/*Nav*/} | ||
<QuestionComponent numQuestion={numQuestion} handleClick={handleClick}/> | ||
|
||
</div>); | ||
} | ||
|
||
function QuestionComponent({numQuestion, handleClick}){ | ||
return ( | ||
<div> | ||
<p>questions[numQuestion].getQuestion()</p> | ||
{questions[numQuestion].getAnswers().map((item, index) => ( | ||
<Answer key={index} text={item} onClick={handleClick}/> | ||
))} | ||
</div> | ||
); | ||
} | ||
|
||
function Answer({text, handleClick}){ | ||
return ( | ||
<button onClick={handleClick}>{text}</button> | ||
); | ||
} | ||
|
||
export default QuestionView; |