diff --git a/src/app/modules/home/form-quiz/form-create-quiz/form-create-quiz.component.ts b/src/app/modules/home/form-quiz/form-create-quiz/form-create-quiz.component.ts index cbc1d924240150c9afec852a19cf43459dc01730..294fc64b9140d18def0612a9adce72eb3150932f 100644 --- a/src/app/modules/home/form-quiz/form-create-quiz/form-create-quiz.component.ts +++ b/src/app/modules/home/form-quiz/form-create-quiz/form-create-quiz.component.ts @@ -3,6 +3,7 @@ import { FormQuizService } from '../../../../services/form-quiz.service'; import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; import { Router } from '@angular/router'; import { MatDialogRef } from '@angular/material/dialog'; +import { QuestionService } from '../../../../services/question.service'; @Component({ selector: 'app-form-create-quiz', @@ -17,7 +18,7 @@ export class FormCreateQuizComponent implements OnInit { difficultyCtrl: any; form: any; - constructor(private formQuizService: FormQuizService, private fb: FormBuilder, private router: Router) { } + constructor(private questionService: QuestionService, private formQuizService: FormQuizService, private fb: FormBuilder, private router: Router) { } categories: { id: number; name: string }[] = []; ngOnInit(): void { this.categoryCtrl = this.fb.control(null, []); @@ -39,11 +40,16 @@ export class FormCreateQuizComponent implements OnInit { submitForm(): void { if (this.form?.valid) { - this.router.navigate(['/play-quiz'], { - queryParams: { - category: this.form.value.category, - nbQuestions: this.form.value.nbQuestion, - difficulty: this.form.value.difficulty, + this.formQuizService.getCategory().subscribe({ + next: (data: any) => { + const categories = this.form.value.category; + const difficulty = this.form.value.difficulty; + const NbQuestion = this.form.value.nbQuestion; + this.questionService.createQuiz(NbQuestion, categories.id, difficulty).subscribe({ + next: (data: any) => { + this.router.navigate(['/play-quiz'], { queryParams: { idQuiz: data.id } }); + }, + }); }, }); } diff --git a/src/app/modules/home/play-quiz/multiple-choice/multiple-choice.component.html b/src/app/modules/home/play-quiz/multiple-choice/multiple-choice.component.html index af63d1c5ae176e91de63a5a9cc212b3fc37abf92..9849738507b91c140e64f6fe4a8de691bb18442c 100644 --- a/src/app/modules/home/play-quiz/multiple-choice/multiple-choice.component.html +++ b/src/app/modules/home/play-quiz/multiple-choice/multiple-choice.component.html @@ -4,6 +4,6 @@ 'good-answer': good_answers[i], 'button-selection': true }"> - {{ answer.text }} + {{ decodeHtml(answer.text) }} </button> </div> \ No newline at end of file diff --git a/src/app/modules/home/play-quiz/multiple-choice/multiple-choice.component.ts b/src/app/modules/home/play-quiz/multiple-choice/multiple-choice.component.ts index b422e51666536414e7234d97c0575a9d18c689b8..fda5bf4125b232ef2b5a16e624a352a08d81835e 100644 --- a/src/app/modules/home/play-quiz/multiple-choice/multiple-choice.component.ts +++ b/src/app/modules/home/play-quiz/multiple-choice/multiple-choice.component.ts @@ -10,7 +10,7 @@ export class MultipleChoiceComponent implements OnInit { @Input() getAnswer!: (id_tested_answer: number) => Promise<number>; good_answers: boolean[] = []; answer_click: number = -1; - constructor() {} + constructor() { } ngOnChanges(changes: SimpleChanges): void { if (changes['answers']) { @@ -19,7 +19,13 @@ export class MultipleChoiceComponent implements OnInit { } } - ngOnInit(): void {} + decodeHtml(html: string): string { + const textArea = document.createElement('textarea'); + textArea.innerHTML = html; + return textArea.value; + } + + ngOnInit(): void { } async handleClick(id_answer: number, position: number) { const right_answer = await this.getAnswer(id_answer); diff --git a/src/app/modules/home/play-quiz/play-quiz.component.html b/src/app/modules/home/play-quiz/play-quiz.component.html index 92ca9818105b9e658db8a50b35063a2408314d58..d2897dada9e4c04ce983cc926e74023f5d643eb0 100644 --- a/src/app/modules/home/play-quiz/play-quiz.component.html +++ b/src/app/modules/home/play-quiz/play-quiz.component.html @@ -4,8 +4,8 @@ <div class="title"> <h4>Question {{ actualQuestionIndex + 1 }}/{{ quiz.questions.length }}</h4> <h5>Score : {{ score }}/{{ quiz.questions.length }}</h5> - <h5>Category : {{ actualQuestion.category.name }}</h5> - <h2>{{ actualQuestion.text }}</h2> + <h5>Category : {{ decodeHtml(actualQuestion.category.name) }}</h5> + <h2>{{ decodeHtml(actualQuestion.text) }}</h2> </div> </div> <div class="answer-container" [class.disabled]="showNextQuestion"> diff --git a/src/app/modules/home/play-quiz/play-quiz.component.ts b/src/app/modules/home/play-quiz/play-quiz.component.ts index b90f3658f5ff761f4e1800bc3ffbc93dd07f2d41..71067f09389030b51a29319cfcf2c988eb3c57cc 100644 --- a/src/app/modules/home/play-quiz/play-quiz.component.ts +++ b/src/app/modules/home/play-quiz/play-quiz.component.ts @@ -37,6 +37,13 @@ export class PlayQuizComponent implements OnInit { }); } + decodeHtml(html: string): string { + const textArea = document.createElement('textarea'); + textArea.innerHTML = html; + return textArea.value; + } + + nextQuestion() { if (this.actualQuestionIndex === this.quiz.questionIndex - 1 + this.quiz.questions.length - 1) { Swal.fire({