Skip to content

Commit 58f60c9

Browse files
authored
Merge pull request #52 from xpquiz/develop
v1.3.3
2 parents d2c27a1 + fdfa9ad commit 58f60c9

File tree

5 files changed

+45
-39
lines changed

5 files changed

+45
-39
lines changed

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.3.2",
3+
"version": "1.3.3",
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.3.2</label>
4+
<label><b>XPQuiz</b>&nbsp;- Version 1.3.3</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/main-window/main-window.component.ts

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,27 @@ export class MainWindowComponent implements OnInit {
3434
await this.router.navigateByUrl(route);
3535
}
3636

37-
private startCountdown(): void {
37+
private async startCountdown(): Promise<void> {
3838
const appStorage: AppStorage = this.appStorageService.retrieveAppStorage();
3939

4040
if (appStorage.lastQuizResponseDate === null) return;
4141

4242
const nextResponseMinimumDate: Moment = moment(appStorage.lastQuizResponseDate).add(3, "hours");
4343

44-
new Promise<void>(async (resolve): Promise<void> => {
45-
while (true) {
46-
const now: Moment = moment();
44+
while (true) {
45+
const now: Moment = moment();
4746

48-
if (now.isSame(nextResponseMinimumDate) || now.isAfter(nextResponseMinimumDate)) {
49-
this.quizCanBeAnswered = true;
50-
this.appStorageService.clearLastAnsweredDate();
51-
resolve();
52-
break;
53-
}
47+
if (now.isSame(nextResponseMinimumDate) || now.isAfter(nextResponseMinimumDate)) {
48+
this.quizCanBeAnswered = true;
49+
this.appStorageService.clearLastAnsweredDate();
50+
break;
51+
}
5452

55-
const timeLeft: Duration = moment.duration(nextResponseMinimumDate.valueOf() - now.valueOf());
53+
const timeLeft: Duration = moment.duration(nextResponseMinimumDate.valueOf() - now.valueOf());
5654

57-
this.remainingTime = `${timeLeft.hours()} hours, ${timeLeft.minutes()} minutes, ${timeLeft.seconds()} seconds`
55+
this.remainingTime = `${timeLeft.hours()} hours, ${timeLeft.minutes()} minutes, ${timeLeft.seconds()} seconds`
5856

59-
await new Promise(f => setTimeout(f, 1000));
60-
}
61-
});
57+
await new Promise(f => setTimeout(f, 1000));
58+
}
6259
}
6360
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
<div class="window window_question">
33
<app-window-title-bar iconPath="question.png" title="Question!"></app-window-title-bar>
44
<div class="window-body window_question_body">
5-
<ng-container *ngIf="!this.questionLoaded">
5+
<ng-container *ngIf="!this.showQuestion">
66
<div class="window_question_body_loading">
77
<label class="window_question_body_loading_title">Loading your question, please hold on a moment...</label>
88
<progress class="window_question_body_loading_progress" max="100" [value]="this.loadingProgressBar"></progress>
99
</div>
1010
</ng-container>
1111

12-
<ng-container *ngIf="this.questionLoaded">
12+
<ng-container *ngIf="this.showQuestion">
1313
<div class="window_question_body_loaded">
1414
<label class="window_question_body_loaded_title">{{this.question}}</label>
1515
<label class="window_question_body_loaded_points">[{{this.questionPoints}} point(s) for this question]</label>

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

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
import {Component, OnInit} from '@angular/core';
1+
import {Component, OnDestroy, OnInit} from '@angular/core';
22
import {TriviaService} from "../../service/trivia.service";
33
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";
77
import {QuestionResultTemplateParams} from "../../model/Template";
88
import {EncryptionService} from "../../service/encryption.service";
9+
import {Subscription} from "rxjs";
910

1011
@Component({
1112
selector: 'app-question-window',
1213
templateUrl: './question-window.component.html',
1314
styleUrls: ['./question-window.component.sass']
1415
})
15-
export class QuestionWindowComponent implements OnInit {
16+
export class QuestionWindowComponent implements OnInit, OnDestroy {
1617

1718
public questionLoaded: boolean = false;
19+
public showQuestion: boolean = false;
1820
public question: string = '';
1921
public questionPoints: number = 0;
2022
public answers: string[] = [];
@@ -27,6 +29,7 @@ export class QuestionWindowComponent implements OnInit {
2729
private questionReadySound: HTMLAudioElement = new Audio('assets/sounds/logon.wav');
2830
private confirmAnswerSound: HTMLAudioElement = new Audio('assets/sounds/exclamation.wav');
2931
private correctAnswer: string = '';
32+
private getQuizzesSubscription: Subscription | undefined;
3033

3134
constructor(
3235
private readonly triviaService: TriviaService,
@@ -43,7 +46,11 @@ export class QuestionWindowComponent implements OnInit {
4346
}
4447

4548
this.startLoadingProgressBar();
46-
await this.loadQuestion();
49+
this.loadQuestion();
50+
}
51+
52+
public ngOnDestroy() {
53+
this.getQuizzesSubscription?.unsubscribe();
4754
}
4855

4956
public async onClickAnswer(selectedAnswer: string) {
@@ -57,8 +64,8 @@ export class QuestionWindowComponent implements OnInit {
5764
return selectedAnswer ? `> ${answer} <` : answer;
5865
}
5966

60-
private async loadQuestion() {
61-
this.triviaService.getQuizzes().subscribe(async (response: TriviaResponse[]): Promise<void> => {
67+
private loadQuestion(): void {
68+
this.getQuizzesSubscription = this.triviaService.getQuizzes().subscribe((response: TriviaResponse[]): void => {
6269
const singleQuiz: TriviaResponse = response[0];
6370

6471
this.question = singleQuiz.question.text;
@@ -68,13 +75,8 @@ export class QuestionWindowComponent implements OnInit {
6875
.sort((a, b) => a.sort - b.sort)
6976
.map(({value}) => value);
7077

71-
await new Promise(f => setTimeout(f, 3000));
72-
73-
this.questionLoaded = true;
74-
75-
await this.questionReadySound.play();
76-
7778
this.questionPoints = this.sumQuestionPoints(singleQuiz.difficulty, singleQuiz.isNiche);
79+
this.questionLoaded = true;
7880
});
7981
}
8082

@@ -124,19 +126,26 @@ export class QuestionWindowComponent implements OnInit {
124126
return questionPoints + nichePoints;
125127
}
126128

127-
private startLoadingProgressBar(): void {
128-
new Promise<void>(async (resolve, reject): Promise<void> => {
129-
while (true) {
130-
this.loadingProgressBar += 10;
129+
private async startLoadingProgressBar(): Promise<void> {
130+
let revertProgressBar: boolean = false;
131131

132-
if (this.loadingProgressBar === this.progressBarMax) {
133-
resolve();
132+
while (true) {
133+
if(this.loadingProgressBar === 100) {
134+
revertProgressBar = true;
135+
136+
if(this.questionLoaded){
137+
this.showQuestion = true;
138+
await this.questionReadySound.play();
134139
break;
135140
}
136-
137-
await new Promise(f => setTimeout(f, 300));
141+
} else if(this.loadingProgressBar === 0) {
142+
revertProgressBar = false;
138143
}
139-
});
144+
145+
this.loadingProgressBar += revertProgressBar ? -10 : 10;
146+
147+
await new Promise(f => setTimeout(f, 300));
148+
}
140149
}
141150

142151
private async returnHome() {

0 commit comments

Comments
 (0)