Skip to content

Commit f61ddca

Browse files
authored
Merge pull request #34 from xpquiz/develop
v1.2.0
2 parents c936f51 + 845a252 commit f61ddca

18 files changed

+193
-23
lines changed

package-lock.json

Lines changed: 20 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "xpquiz.github.io",
3-
"version": "1.1.0",
3+
"version": "1.2.0",
44
"scripts": {
55
"ng": "ng",
66
"start": "ng serve",
@@ -22,6 +22,7 @@
2222
"angular-cli-ghpages": "^1.0.6",
2323
"crypto-js": "^4.1.1",
2424
"moment": "^2.29.4",
25+
"mustache": "^4.2.0",
2526
"rxjs": "~7.8.0",
2627
"tslib": "^2.3.0",
2728
"xp.css": "^0.2.6",
@@ -32,6 +33,7 @@
3233
"@angular/cli": "~16.1.6",
3334
"@angular/compiler-cli": "^16.1.0",
3435
"@types/jasmine": "~4.3.0",
36+
"@types/mustache": "^4.2.2",
3537
"jasmine-core": "~4.6.0",
3638
"karma": "~6.4.0",
3739
"karma-chrome-launcher": "~3.2.0",

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.1.0</label>
4+
<label><b>XPQuiz</b>&nbsp;- Version 1.2.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/about-window/about-window.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Component} from '@angular/core';
22
import {Router} from "@angular/router";
3-
import {PathsEnum} from "../../model/PathsEnum";
3+
import {PathsEnum} from "../../model/enums/PathsEnum";
44

55
@Component({
66
selector: 'app-about-window',

src/app/app-routing.module.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {RouterModule, Routes} from '@angular/router';
33
import {QuestionWindowComponent} from "./question-window/question-window.component";
44
import {MainWindowComponent} from "./main-window/main-window.component";
55
import {ScoreWindowComponent} from "./score-window/score-window.component";
6-
import {PathsEnum} from "../model/PathsEnum";
6+
import {PathsEnum} from "../model/enums/PathsEnum";
77
import {CorrectAnswerWindowComponent} from "./correct-answer-window/correct-answer-window.component";
88
import {WrongAnswerWindowComponent} from "./wrong-answer-window/wrong-answer-window.component";
99
import {AboutWindowComponent} from "./about-window/about-window.component";

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import {Component, OnInit} from '@angular/core';
22
import {ActivatedRoute, Router} from "@angular/router";
3-
import {PathsEnum} from "../../model/PathsEnum";
3+
import {PathsEnum} from "../../model/enums/PathsEnum";
44
import {StorageService} from "../../service/storage.service";
55
import {AppStorage, WeekScore} from "../../model/AppStorage";
66
import * as moment from "moment";
7+
import {Moment} from "moment/moment";
78

89
@Component({
910
selector: 'app-correct-answer-window',
@@ -25,10 +26,29 @@ export class CorrectAnswerWindowComponent implements OnInit {
2526
}
2627

2728
public async ngOnInit(): Promise<void> {
29+
const quizCanBeAnswered: boolean = this.checkIfQuizCanBeAnswered();
30+
31+
if (!quizCanBeAnswered) {
32+
await this.returnHome();
33+
return;
34+
}
35+
2836
await this.correctAnswerSound.play();
2937
this.saveCurrentScore();
3038
}
3139

40+
private checkIfQuizCanBeAnswered(): boolean {
41+
const appStorage: AppStorage = this.storageService.get();
42+
const lastQuizResponseDate: string | null = appStorage.lastQuizResponseDate;
43+
44+
if (lastQuizResponseDate === null) return true;
45+
46+
const now: Moment = moment();
47+
const nextResponseMinimumDate: Moment = moment(lastQuizResponseDate).add(3, "hours");
48+
49+
return now.isSame(nextResponseMinimumDate) || now.isAfter(nextResponseMinimumDate);
50+
}
51+
3252
public async returnHome(): Promise<void> {
3353
await this.router.navigateByUrl(PathsEnum.HOME);
3454
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {Component, OnInit} from '@angular/core';
22
import {StorageService} from "../../service/storage.service";
33
import {Router} from "@angular/router";
4-
import {PathsEnum} from "../../model/PathsEnum";
4+
import {PathsEnum} from "../../model/enums/PathsEnum";
55
import {AppStorage} from "../../model/AppStorage";
66
import * as moment from "moment";
77
import {Duration, Moment} from "moment";

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@ import {Component, OnInit} from '@angular/core';
22
import {TriviaService} from "../../service/trivia.service";
33
import {TriviaResponse} from "../../model/TriviaResponse";
44
import {Router} from "@angular/router";
5-
import {PathsEnum} from "../../model/PathsEnum";
5+
import {PathsEnum} from "../../model/enums/PathsEnum";
6+
import {AppStorage} from "../../model/AppStorage";
7+
import {Moment} from "moment";
8+
import * as moment from "moment/moment";
9+
import {StorageService} from "../../service/storage.service";
610

711
@Component({
812
selector: 'app-question-window',
@@ -27,15 +31,35 @@ export class QuestionWindowComponent implements OnInit {
2731

2832
constructor(
2933
private readonly triviaService: TriviaService,
30-
private readonly router: Router
34+
private readonly router: Router,
35+
private readonly storageService: StorageService
3136
) {
3237
}
3338

3439
public async ngOnInit(): Promise<void> {
40+
const quizCanBeAnswered: boolean = this.checkIfQuizCanBeAnswered();
41+
42+
if (!quizCanBeAnswered) {
43+
await this.returnHome();
44+
return;
45+
}
46+
3547
this.startLoadingProgressBar();
3648
await this.loadQuestion();
3749
}
3850

51+
private checkIfQuizCanBeAnswered(): boolean {
52+
const appStorage: AppStorage = this.storageService.get();
53+
const lastQuizResponseDate: string | null = appStorage.lastQuizResponseDate;
54+
55+
if (lastQuizResponseDate === null) return true;
56+
57+
const now: Moment = moment();
58+
const nextResponseMinimumDate: Moment = moment(lastQuizResponseDate).add(3, "hours");
59+
60+
return now.isSame(nextResponseMinimumDate) || now.isAfter(nextResponseMinimumDate);
61+
}
62+
3963
public async onClickAnswer(selectedAnswer: string) {
4064
this.selectedAnswer = selectedAnswer;
4165
await this.confirmAnswerSound.play();
@@ -124,4 +148,8 @@ export class QuestionWindowComponent implements OnInit {
124148
}
125149
});
126150
}
151+
152+
private async returnHome() {
153+
await this.router.navigateByUrl(PathsEnum.HOME);
154+
}
127155
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818
</div>
1919

2020
<div class="window-body_buttons">
21-
<app-icon-button iconPath="copy.png" title="Copy score to clipboard" [copy-clipboard]="this.clipboardMessage"></app-icon-button>
21+
<app-icon-button iconPath="copy.png" title="Share score" [copy-clipboard]="this.clipboardText" (click)="this.showClipboardMessage()"></app-icon-button>
2222
<app-icon-button iconPath="home.png" title="Return to home"
2323
(onButtonClick)="this.returnHome()"></app-icon-button>
2424
</div>
25+
<div *ngIf="this.displayClipboardMessage">
26+
<label class="window-body_clipboard-text">Score copied to clipboard!</label>
27+
</div>
2528
</div>
2629
</div>

src/app/score-window/score-window.component.sass

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,8 @@
4040

4141
app-icon-button
4242
margin: 3px
43+
44+
&_clipboard-text
45+
color: green
46+
font-weight: bold
47+
margin: 5px

0 commit comments

Comments
 (0)