Skip to content

Commit aa6952c

Browse files
authored
Merge pull request #44 from xpquiz/develop
v1.3.0
2 parents b286398 + b08908c commit aa6952c

19 files changed

+217
-54
lines changed

angular.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
"zone.js"
2525
],
2626
"allowedCommonJsDependencies": [
27-
"crypto-js"
27+
"crypto-js",
28+
"moment"
2829
],
2930
"tsConfig": "tsconfig.app.json",
3031
"inlineStyleLanguage": "sass",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "xpquiz.github.io",
3-
"version": "1.2.2",
3+
"version": "1.3.0",
44
"scripts": {
55
"ng": "ng",
66
"start": "ng serve",

src/app/about-window/about-window.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<div class="window">
22
<app-window-title-bar iconPath="about.png" title="About XPQuiz"></app-window-title-bar>
33
<div class="window-body">
4-
<label><b>XPQuiz</b>&nbsp;- Version 1.2.2</label>
4+
<label><b>XPQuiz</b>&nbsp;- Version 1.3.0</label>
55
<label class="main">Created by&nbsp;<b><a href="https://isahann.github.io">Isahann Hanacleto</a></b></label>
66

77
<label>Source code at&nbsp;<b><a href="https://github.com/xpquiz/xpquiz.github.io">GitHub</a></b></label>

src/app/app-routing.module.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ const routes: Routes = [
3131
component: QuestionWindowComponent,
3232
},
3333
{
34-
path: `${PathsEnum.CORRECT_ANSWER}/:points`,
34+
path: `${PathsEnum.CORRECT_ANSWER}/:points/:result`,
3535
component: CorrectAnswerWindowComponent,
3636
},
3737
{
38-
path: `${PathsEnum.WRONG_ANSWER}/:answer`,
38+
path: `${PathsEnum.WRONG_ANSWER}/:result`,
3939
component: WrongAnswerWindowComponent
4040
}
4141
]

src/app/correct-answer-window/correct-answer-window.component.html

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@
66
<label>You earned {{this.questionScore}} points!</label>
77
<label>Come back in 3 hours for another question!</label>
88
</div>
9-
10-
<app-icon-button iconPath="home.png" title="Return to home"
11-
(onButtonClick)="this.returnHome()"></app-icon-button>
9+
<div class="window-body_buttons">
10+
<app-icon-button iconPath="copy.png" title="Share result" [copy-clipboard]="this.clipboardText"
11+
(onButtonClick)="this.showClipboardMessage()"></app-icon-button>
12+
<app-icon-button iconPath="home.png" title="Return to home"
13+
(onButtonClick)="this.returnHome()"></app-icon-button>
14+
</div>
15+
<div *ngIf="this.displayClipboardMessage">
16+
<label class="window-body_clipboard-text">Question result copied to clipboard!</label>
17+
</div>
1218
</div>
1319
</div>

src/app/correct-answer-window/correct-answer-window.component.sass

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,17 @@
1414
label
1515
text-align: center
1616
margin: 5px
17+
18+
&_buttons
19+
display: flex
20+
flex-direction: row
21+
align-items: center
22+
justify-content: space-between
23+
24+
app-icon-button
25+
margin: 3px
26+
27+
&_clipboard-text
28+
color: green
29+
font-weight: bold
30+
margin: 5px

src/app/correct-answer-window/correct-answer-window.component.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import {Component, OnInit} from '@angular/core';
22
import {ActivatedRoute, Router} from "@angular/router";
33
import {PathsEnum} from "../../model/enums/PathsEnum";
44
import {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";
1114
export 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
}

src/app/question-window/question-window.component.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {TriviaResponse} from "../../model/TriviaResponse";
44
import {Router} from "@angular/router";
55
import {PathsEnum} from "../../model/enums/PathsEnum";
66
import {AppStorageService} from "../../service/app-storage.service";
7+
import {QuestionResultTemplateParams} from "../../model/enums/Template";
8+
import {EncryptionService} from "../../service/encryption.service";
79

810
@Component({
911
selector: 'app-question-window',
@@ -29,6 +31,7 @@ export class QuestionWindowComponent implements OnInit {
2931
constructor(
3032
private readonly triviaService: TriviaService,
3133
private readonly router: Router,
34+
private readonly encryptionService: EncryptionService,
3235
private readonly appStorageService: AppStorageService
3336
) {
3437
}
@@ -96,11 +99,21 @@ export class QuestionWindowComponent implements OnInit {
9699

97100
private async redirectFromAnswer(): Promise<void> {
98101
const correctAnswer: boolean = this.selectedAnswer === this.correctAnswer;
102+
const questionResult: QuestionResultTemplateParams = {
103+
question: this.question,
104+
selectedAnswer: `${correctAnswer ? '🟩' : '🟥'} ${this.selectedAnswer}`,
105+
rightAnswer: this.correctAnswer,
106+
wrongAnswers: this.answers.filter(value => value !== this.correctAnswer)
107+
};
108+
109+
const questionResultData: string = this.encryptionService.encrypt(JSON.stringify(questionResult));
99110

100111
if (correctAnswer) {
101-
await this.router.navigate([PathsEnum.CORRECT_ANSWER, this.questionPoints]);
112+
const questionPointsData: string = this.encryptionService.encrypt(this.questionPoints.toString());
113+
114+
await this.router.navigate([PathsEnum.CORRECT_ANSWER, questionPointsData, questionResultData]);
102115
} else {
103-
await this.router.navigate([PathsEnum.WRONG_ANSWER, this.correctAnswer]);
116+
await this.router.navigate([PathsEnum.WRONG_ANSWER, questionResultData]);
104117
}
105118
}
106119

src/app/wrong-answer-window/wrong-answer-window.component.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@
66
<label>Come back in 3 hours for another question!</label>
77
</div>
88

9-
<app-icon-button iconPath="home.png" title="Return to home"
10-
(onButtonClick)="this.returnHome()"></app-icon-button>
9+
<div class="window-body_buttons">
10+
<app-icon-button iconPath="copy.png" title="Share result" [copy-clipboard]="this.clipboardText"
11+
(onButtonClick)="this.showClipboardMessage()"></app-icon-button>
12+
<app-icon-button iconPath="home.png" title="Return to home"
13+
(onButtonClick)="this.returnHome()"></app-icon-button>
14+
</div>
15+
<div *ngIf="this.displayClipboardMessage">
16+
<label class="window-body_clipboard-text">Question result copied to clipboard!</label>
17+
</div>
1118
</div>
1219
</div>

src/app/wrong-answer-window/wrong-answer-window.component.sass

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,16 @@
1313
label
1414
margin: 5px
1515

16+
&_buttons
17+
display: flex
18+
flex-direction: row
19+
align-items: center
20+
justify-content: space-between
21+
22+
app-icon-button
23+
margin: 3px
1624

25+
&_clipboard-text
26+
color: green
27+
font-weight: bold
28+
margin: 5px

0 commit comments

Comments
 (0)