Skip to content

Commit a438ab7

Browse files
committed
#67 refactoring methods
1 parent 7706c10 commit a438ab7

File tree

10 files changed

+22
-33
lines changed

10 files changed

+22
-33
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
at DeviantArt</a></b></label>
1616

1717
<app-icon-button iconPath="home.png" title="Return to home"
18-
(onButtonClick)="this.returnHome()"></app-icon-button>
18+
(onButtonClick)="this.router.navigateByUrl(PathsEnum.HOME)"></app-icon-button>
1919
</div>
2020
</div>

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ import {PathsEnum} from "../../model/enums/PathsEnum";
99
})
1010
export class AboutWindowComponent {
1111

12+
protected readonly PathsEnum = PathsEnum;
13+
1214
constructor(
13-
private readonly router: Router
15+
public readonly router: Router
1416
) {
1517
}
1618

17-
public async returnHome(): Promise<void> {
18-
await this.router.navigateByUrl(PathsEnum.HOME);
19-
}
2019
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<app-icon-button iconPath="copy.png" title="Share result" [copy-clipboard]="this.clipboardText"
1111
(onButtonClick)="this.showClipboardMessage()"></app-icon-button>
1212
<app-icon-button iconPath="home.png" title="Return to home"
13-
(onButtonClick)="this.returnHome()"></app-icon-button>
13+
(onButtonClick)="this.router.navigateByUrl(PathsEnum.HOME);"></app-icon-button>
1414
</div>
1515
<div *ngIf="this.displayClipboardMessage">
1616
<label class="window-body_clipboard-text">Question result copied to clipboard!</label>

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ import {GameMode} from "../../model/enums/GameModesEnum";
1414
})
1515
export class CorrectAnswerWindowComponent implements OnInit {
1616

17+
protected readonly PathsEnum = PathsEnum;
18+
1719
public questionScore: number = 0;
1820
public clipboardText: string = '';
1921
public displayClipboardMessage: boolean = false;
2022

2123
private correctAnswerSound: HTMLAudioElement = new Audio('assets/sounds/tada.wav');
2224

2325
constructor(
24-
private readonly router: Router,
26+
protected readonly router: Router,
2527
private readonly route: ActivatedRoute,
2628
private readonly encryptionService: EncryptionService,
2729
private readonly templateService: TemplateService,
@@ -33,18 +35,14 @@ export class CorrectAnswerWindowComponent implements OnInit {
3335
await this.retrieveRouteParams();
3436

3537
if (!this.appStorageService.canQuizBeAnswered()) {
36-
await this.returnHome();
38+
await this.router.navigateByUrl(PathsEnum.HOME);
3739
return;
3840
}
3941

4042
await this.correctAnswerSound.play();
4143
this.saveCurrentScore();
4244
}
4345

44-
public async returnHome(): Promise<void> {
45-
await this.router.navigateByUrl(PathsEnum.HOME);
46-
}
47-
4846
public async showClipboardMessage(): Promise<void> {
4947
this.displayClipboardMessage = true;
5048

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212

1313
<div class="window-body_buttons">
1414
<app-icon-button iconPath="quiz.png" title="New quiz"
15-
(onButtonClick)="this.redirectTo(PathsEnum.GAME_MODE)"
15+
(onButtonClick)="this.router.navigateByUrl(PathsEnum.GAME_MODE)"
1616
[disabled]="!this.quizCanBeAnswered"></app-icon-button>
1717
<app-icon-button iconPath="score.png" title="My score"
18-
(onButtonClick)="this.redirectTo(PathsEnum.SCORES)"></app-icon-button>
18+
(onButtonClick)="this.router.navigateByUrl(PathsEnum.SCORES)"></app-icon-button>
1919
<app-icon-button iconPath="about.png" title="About"
20-
(onButtonClick)="this.redirectTo(PathsEnum.ABOUT)"></app-icon-button>
20+
(onButtonClick)="this.router.navigateByUrl(PathsEnum.ABOUT)"></app-icon-button>
2121
</div>
2222
</div>
2323
</div>

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class MainWindowComponent implements OnInit {
1818
protected readonly PathsEnum = PathsEnum;
1919

2020
constructor(
21-
private readonly router: Router,
21+
protected readonly router: Router,
2222
private readonly appStorageService: AppStorageService
2323
) {
2424
}
@@ -30,10 +30,6 @@ export class MainWindowComponent implements OnInit {
3030
this.startCountdown();
3131
}
3232

33-
public async redirectTo(route: PathsEnum): Promise<void> {
34-
await this.router.navigateByUrl(route);
35-
}
36-
3733
private async startCountdown(): Promise<void> {
3834
const appStorage: AppStorage = this.appStorageService.retrieveAppStorage();
3935

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
<app-icon-button iconPath="copy.png" title="Share score" [copy-clipboard]="this.clipboardText"
6868
(click)="this.showClipboardMessage()"></app-icon-button>
6969
<app-icon-button iconPath="home.png" title="Return to home"
70-
(onButtonClick)="this.returnHome()"></app-icon-button>
70+
(onButtonClick)="this.router.navigateByUrl(PathsEnum.HOME)"></app-icon-button>
7171
</div>
7272
<div *ngIf="this.displayClipboardMessage">
7373
<label class="window-body_clipboard-text">Score copied to clipboard!</label>

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class ScoreWindowComponent implements OnInit {
2222
public displayClipboardMessage: boolean = false;
2323

2424
constructor(
25-
private readonly router: Router,
25+
protected readonly router: Router,
2626
private readonly templateService: TemplateService,
2727
private readonly appStorageService: AppStorageService
2828
) {
@@ -33,10 +33,6 @@ export class ScoreWindowComponent implements OnInit {
3333
await this.assembleClipboardText();
3434
}
3535

36-
public async returnHome(): Promise<void> {
37-
await this.router.navigateByUrl(PathsEnum.HOME);
38-
}
39-
4036
public async showClipboardMessage(): Promise<void> {
4137
this.displayClipboardMessage = true;
4238

@@ -75,4 +71,6 @@ export class ScoreWindowComponent implements OnInit {
7571
this.currentYear = currentYear;
7672
this.currentWeek = currentWeek;
7773
}
74+
75+
protected readonly PathsEnum = PathsEnum;
7876
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<app-icon-button iconPath="copy.png" title="Share result" [copy-clipboard]="this.clipboardText"
1212
(onButtonClick)="this.showClipboardMessage()"></app-icon-button>
1313
<app-icon-button iconPath="home.png" title="Return to home"
14-
(onButtonClick)="this.returnHome()"></app-icon-button>
14+
(onButtonClick)="this.router.navigateByUrl(PathsEnum.HOME)"></app-icon-button>
1515
</div>
1616
<div *ngIf="this.displayClipboardMessage">
1717
<label class="window-body_clipboard-text">Question result copied to clipboard!</label>

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class WrongAnswerWindowComponent implements OnInit {
2222
private wrongAnswerSound: HTMLAudioElement = new Audio('assets/sounds/critical_stop.wav');
2323

2424
constructor(
25-
private readonly router: Router,
25+
protected readonly router: Router,
2626
private readonly route: ActivatedRoute,
2727
private readonly encryptionService: EncryptionService,
2828
private readonly templateService: TemplateService,
@@ -34,18 +34,14 @@ export class WrongAnswerWindowComponent implements OnInit {
3434
await this.retrieveRouteParams();
3535

3636
if (!this.appStorageService.canQuizBeAnswered()) {
37-
await this.returnHome();
37+
await this.router.navigateByUrl(PathsEnum.HOME);
3838
return;
3939
}
4040

4141
await this.wrongAnswerSound.play();
4242
this.saveCurrentScore();
4343
}
4444

45-
public async returnHome(): Promise<void> {
46-
await this.router.navigateByUrl(PathsEnum.HOME);
47-
}
48-
4945
public async showClipboardMessage(): Promise<void> {
5046
this.displayClipboardMessage = true;
5147

@@ -71,4 +67,6 @@ export class WrongAnswerWindowComponent implements OnInit {
7167
this.correctAnswers = 'questions' in questionResult ? questionResult.correctAnswers : [questionResult.rightAnswer];
7268
this.clipboardText = await this.templateService.render(gameMode.templateEnum, questionResult);
7369
}
70+
71+
protected readonly PathsEnum = PathsEnum;
7472
}

0 commit comments

Comments
 (0)