Skip to content

Commit e9d23b6

Browse files
committed
fix(help): change lifecycle hook from ngAfterViewInit to ngOnInit for statsGroups initialization
1 parent d7cc600 commit e9d23b6

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/app/components/help/help.component.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ describe('HelpComponent', () => {
173173
};
174174
jest.spyOn(localstorageService, 'getScore').mockReturnValue({ playCount: 1, bestTime: 100 });
175175

176-
component.ngAfterViewInit();
176+
component.ngOnInit();
177177
fixture.detectChanges();
178178
});
179179

src/app/components/help/help.component.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, inject, output, AfterViewInit } from '@angular/core';
1+
import { Component, inject, output, AfterViewInit, type OnInit } from '@angular/core';
22
import { TranslatePipe, TranslateService } from '@ngx-translate/core';
33
import { clickExternalHref } from '../../model/external-links';
44
import { GameModes } from '../../model/consts';
@@ -23,7 +23,7 @@ interface StatGroup {
2323
styleUrls: ['./help.component.scss'],
2424
imports: [TranslatePipe, DurationPipe]
2525
})
26-
export class HelpComponent implements AfterViewInit {
26+
export class HelpComponent implements OnInit {
2727
readonly showTutorial = output();
2828
readonly gameModes = GameModes;
2929
statsGroups: Array<StatGroup> = [];
@@ -43,7 +43,7 @@ export class HelpComponent implements AfterViewInit {
4343
{ icon: 'icon-logo', key: 'H', name: 'HELP' }
4444
];
4545

46-
ngAfterViewInit(): void {
46+
ngOnInit(): void {
4747
this.statsGroups = this.buildStatsGroups();
4848
}
4949

@@ -73,7 +73,11 @@ export class HelpComponent implements AfterViewInit {
7373

7474
clearTimesClick(): void {
7575
if (confirm(this.translate.instant('BEST_TIMES_CLEAR_SURE'))) {
76-
this.clearTimes().catch(error => console.error(error));
76+
this.clearTimes()
77+
.then(() => {
78+
this.statsGroups = [];
79+
})
80+
.catch(error => console.error(error));
7781
}
7882
}
7983

0 commit comments

Comments
 (0)