@@ -2,6 +2,9 @@ import {Component, OnInit} from '@angular/core';
22import { ActivatedRoute , Router } from "@angular/router" ;
33import { PathsEnum } from "../../model/enums/PathsEnum" ;
44import { AppStorageService } from "../../service/app-storage.service" ;
5+ import { EncryptionService } from "../../service/encryption.service" ;
6+ import { TemplateService } from "../../service/template.service" ;
7+ import { QuestionResultTemplateParams , TemplateEnum } from "../../model/enums/Template" ;
58
69@Component ( {
710 selector : 'app-correct-answer-window' ,
@@ -11,18 +14,23 @@ import {AppStorageService} from "../../service/app-storage.service";
1114export class CorrectAnswerWindowComponent implements OnInit {
1215
1316 public questionScore : number = 0 ;
17+ public clipboardText : string = '' ;
18+ public displayClipboardMessage : boolean = false ;
1419
1520 private correctAnswerSound : HTMLAudioElement = new Audio ( 'assets/sounds/tada.wav' ) ;
1621
1722 constructor (
1823 private readonly router : Router ,
1924 private readonly route : ActivatedRoute ,
25+ private readonly encryptionService : EncryptionService ,
26+ private readonly templateService : TemplateService ,
2027 private readonly appStorageService : AppStorageService
2128 ) {
22- this . questionScore = parseInt ( this . route . snapshot . paramMap . get ( 'points' ) ?? '0' ) ;
2329 }
2430
2531 public async ngOnInit ( ) : Promise < void > {
32+ await this . retrieveRouteParams ( ) ;
33+
2634 if ( ! this . appStorageService . canQuizBeAnswered ( ) ) {
2735 await this . returnHome ( ) ;
2836 return ;
@@ -36,7 +44,28 @@ export class CorrectAnswerWindowComponent implements OnInit {
3644 await this . router . navigateByUrl ( PathsEnum . HOME ) ;
3745 }
3846
47+ public async showClipboardMessage ( ) : Promise < void > {
48+ this . displayClipboardMessage = true ;
49+
50+ await new Promise ( f => setTimeout ( f , 5000 ) ) ;
51+
52+ this . displayClipboardMessage = false ;
53+ }
54+
3955 private saveCurrentScore ( ) : void {
4056 this . appStorageService . saveAnswer ( true , this . questionScore ) ;
4157 }
58+
59+ private async retrieveRouteParams ( ) : Promise < void > {
60+ const encryptedQuestionScore : string = this . route . snapshot . paramMap . get ( 'points' ) ! ;
61+ const encryptedQuestionResult : string = this . route . snapshot . paramMap . get ( 'result' ) ! ;
62+
63+ const decryptedQuestionScore : string = this . encryptionService . decrypt ( encryptedQuestionScore ) ;
64+ const decryptedQuestionResult : string = this . encryptionService . decrypt ( encryptedQuestionResult ) ;
65+ const questionResult : QuestionResultTemplateParams = JSON . parse ( decryptedQuestionResult ) ;
66+ const questionResultText : string = await this . templateService . render ( TemplateEnum . QUESTION_RESULT , questionResult ) ;
67+
68+ this . questionScore = parseInt ( decryptedQuestionScore ) ;
69+ this . clipboardText = questionResultText ;
70+ }
4271}
0 commit comments