Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/app/correct-answer-window/correct-answer-window.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {PathsEnum} from "../../model/enums/PathsEnum";
import {StorageService} from "../../service/storage.service";
import {AppStorage, WeekScore} from "../../model/AppStorage";
import * as moment from "moment";
import {Moment} from "moment/moment";

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

public async ngOnInit(): Promise<void> {
const quizCanBeAnswered: boolean = this.checkIfQuizCanBeAnswered();

if (!quizCanBeAnswered) {
await this.returnHome();
return;
}

await this.correctAnswerSound.play();
this.saveCurrentScore();
}

private checkIfQuizCanBeAnswered(): boolean {
const appStorage: AppStorage = this.storageService.get();
const lastQuizResponseDate: string | null = appStorage.lastQuizResponseDate;

if (lastQuizResponseDate === null) return true;

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

return now.isSame(nextResponseMinimumDate) || now.isAfter(nextResponseMinimumDate);
}

public async returnHome(): Promise<void> {
await this.router.navigateByUrl(PathsEnum.HOME);
}
Expand Down
30 changes: 29 additions & 1 deletion src/app/question-window/question-window.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import {TriviaService} from "../../service/trivia.service";
import {TriviaResponse} from "../../model/TriviaResponse";
import {Router} from "@angular/router";
import {PathsEnum} from "../../model/enums/PathsEnum";
import {AppStorage} from "../../model/AppStorage";
import {Moment} from "moment";
import * as moment from "moment/moment";
import {StorageService} from "../../service/storage.service";

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

constructor(
private readonly triviaService: TriviaService,
private readonly router: Router
private readonly router: Router,
private readonly storageService: StorageService
) {
}

public async ngOnInit(): Promise<void> {
const quizCanBeAnswered: boolean = this.checkIfQuizCanBeAnswered();

if (!quizCanBeAnswered) {
await this.returnHome();
return;
}

this.startLoadingProgressBar();
await this.loadQuestion();
}

private checkIfQuizCanBeAnswered(): boolean {
const appStorage: AppStorage = this.storageService.get();
const lastQuizResponseDate: string | null = appStorage.lastQuizResponseDate;

if (lastQuizResponseDate === null) return true;

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

return now.isSame(nextResponseMinimumDate) || now.isAfter(nextResponseMinimumDate);
}

public async onClickAnswer(selectedAnswer: string) {
this.selectedAnswer = selectedAnswer;
await this.confirmAnswerSound.play();
Expand Down Expand Up @@ -124,4 +148,8 @@ export class QuestionWindowComponent implements OnInit {
}
});
}

private async returnHome() {
await this.router.navigateByUrl(PathsEnum.HOME);
}
}
20 changes: 20 additions & 0 deletions src/app/wrong-answer-window/wrong-answer-window.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {PathsEnum} from "../../model/enums/PathsEnum";
import {StorageService} from "../../service/storage.service";
import {AppStorage, WeekScore} from "../../model/AppStorage";
import * as moment from "moment";
import {Moment} from "moment";

@Component({
selector: 'app-wrong-answer-window',
Expand All @@ -24,10 +25,29 @@ export class WrongAnswerWindowComponent implements OnInit {
}

public async ngOnInit(): Promise<void> {
const quizCanBeAnswered: boolean = this.checkIfQuizCanBeAnswered();

if (!quizCanBeAnswered) {
await this.returnHome();
return;
}

await this.wrongAnswerSound.play();
this.saveCurrentScore();
}

private checkIfQuizCanBeAnswered(): boolean {
const appStorage: AppStorage = this.storageService.get();
const lastQuizResponseDate: string | null = appStorage.lastQuizResponseDate;

if (lastQuizResponseDate === null) return true;

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

return now.isSame(nextResponseMinimumDate) || now.isAfter(nextResponseMinimumDate);
}

public async returnHome(): Promise<void> {
await this.router.navigateByUrl(PathsEnum.HOME);
}
Expand Down