From 315b20025aceaa77a8208b97a4c10efe6b15cc85 Mon Sep 17 00:00:00 2001 From: D3B1RUM4N <elies1.mek03@gmail.com> Date: Fri, 6 Dec 2024 04:05:34 +0100 Subject: [PATCH 1/3] fix: create a quiz --- .../form-create-quiz.component.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) 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 cbc1d92..294fc64 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 } }); + }, + }); }, }); } -- GitLab From 1b16f3e021e1ef14cafecfd6dcf101db569c7cc5 Mon Sep 17 00:00:00 2001 From: D3B1RUM4N <elies1.mek03@gmail.com> Date: Fri, 6 Dec 2024 04:09:21 +0100 Subject: [PATCH 2/3] fix: html text decoded --- .../play-quiz/multiple-choice/multiple-choice.component.html | 2 +- src/app/modules/home/play-quiz/play-quiz.component.html | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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 af63d1c..9849738 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/play-quiz.component.html b/src/app/modules/home/play-quiz/play-quiz.component.html index 92ca981..d2897da 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"> -- GitLab From cedb6555819bbab2e6ddeca9b5792cf04b6967eb Mon Sep 17 00:00:00 2001 From: D3B1RUM4N <elies1.mek03@gmail.com> Date: Fri, 6 Dec 2024 04:12:50 +0100 Subject: [PATCH 3/3] fix: added function to decode --- .../multiple-choice/multiple-choice.component.ts | 10 ++++++++-- src/app/modules/home/play-quiz/play-quiz.component.ts | 7 +++++++ 2 files changed, 15 insertions(+), 2 deletions(-) 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 b422e51..fda5bf4 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.ts b/src/app/modules/home/play-quiz/play-quiz.component.ts index b90f365..71067f0 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({ -- GitLab