Skip to content

Commit ea17142

Browse files
committed
chore(app): remove @ngrx/component library
1 parent 051e922 commit ea17142

4 files changed

Lines changed: 68 additions & 79 deletions

File tree

package-lock.json

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

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
"@commitlint/cli": "20.1.0",
5252
"@commitlint/config-conventional": "20.0.0",
5353
"@eslint/js": "9.38.0",
54-
"@ngrx/component": "20.1.0",
5554
"@playwright/test": "1.56.1",
5655
"@types/node": "24.9.2",
5756
"@typescript-eslint/eslint-plugin": "8.46.2",
@@ -88,7 +87,7 @@
8887
"wait-on": "9.0.1"
8988
},
9089
"engines": {
91-
"node": ">=20.0.0 <24",
90+
"node": ">=22.0.0 <24",
9291
"npm": ">=9.0.0"
9392
},
9493
"private": true
Lines changed: 37 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,48 @@
11
<main>
22
<h1 class="first-heading__title" i18n>My Pokemon</h1>
3-
<ng-container *ngrxLet="userPokemons$ as userPokemons; suspenseTpl: loading">
3+
4+
@if (userPokemons().length >= 0) {
45
<div class="my-pokemon__search-container">
56
<app-pokemon-search-input
6-
[title]="userPokemons?.length ? translations.findMore : translations.findPokemon"
7+
[title]="userPokemons().length ? translations.findMore : translations.findPokemon"
78
/>
89
</div>
10+
}
911

10-
@if (!userPokemons?.length) {
11-
<div class="pokemons-empty__container">
12-
<div>
13-
<p i18n>
14-
Uh-oh, it looks like you haven’t caught any Pokémon yet! Need help finding a pokemon?
15-
Try using the search bar to track them down. Gotta catch ‘em all!
16-
</p>
17-
</div>
18-
<div>
19-
<img
20-
class="pokemons-empty__image"
21-
alt="ash jumping with a pokeball"
22-
i18n-alt
23-
ngSrc="angularexampleapp/assets/images/ash-jumping.png"
24-
width="675"
25-
height="1280"
26-
/>
27-
</div>
12+
@if (!userPokemons().length) {
13+
<div class="pokemons-empty__container">
14+
<div>
15+
<p i18n>
16+
Uh-oh, it looks like you haven’t caught any Pokémon yet! Need help finding a pokemon? Try
17+
using the search bar to track them down. Gotta catch ‘em all!
18+
</p>
19+
</div>
20+
<div>
21+
<img
22+
class="pokemons-empty__image"
23+
alt="ash jumping with a pokeball"
24+
i18n-alt
25+
ngSrc="angularexampleapp/assets/images/ash-jumping.png"
26+
width="675"
27+
height="1280"
28+
/>
2829
</div>
29-
} @else {
30-
<ul class="my-pokemon__grid">
31-
@for (pokemon of userPokemons$ | ngrxPush; track pokemon.id) {
32-
<li>
33-
<app-pokemon-card [pokemon]="pokemon" />
34-
</li>
35-
}
36-
</ul>
37-
}
38-
</ng-container>
39-
<ng-template #loading>
30+
</div>
31+
} @else {
32+
<ul class="my-pokemon__grid">
33+
@for (pokemon of userPokemons(); track pokemon.id) {
34+
<li>
35+
<app-pokemon-card [pokemon]="pokemon" />
36+
</li>
37+
}
38+
</ul>
39+
}
40+
41+
@if (loading()) {
4042
<ul class="my-pokemon__grid">
41-
<li>
42-
<app-pokemon-card [loading]="true" />
43-
</li>
44-
<li>
45-
<app-pokemon-card [loading]="true" />
46-
</li>
47-
<li>
48-
<app-pokemon-card [loading]="true" />
49-
</li>
43+
<li><app-pokemon-card [loading]="true" /></li>
44+
<li><app-pokemon-card [loading]="true" /></li>
45+
<li><app-pokemon-card [loading]="true" /></li>
5046
</ul>
51-
</ng-template>
47+
}
5248
</main>
Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
import { ChangeDetectionStrategy, Component, CUSTOM_ELEMENTS_SCHEMA, inject } from '@angular/core';
1+
import {
2+
ChangeDetectionStrategy,
3+
Component,
4+
CUSTOM_ELEMENTS_SCHEMA,
5+
inject,
6+
signal,
7+
} from '@angular/core';
8+
import { toSignal } from '@angular/core/rxjs-interop';
29
import { UserService } from '~features/authentication/services/user.service';
310
import { PokemonService } from '~features/pokemon/services/pokemon.service';
411
import { NgOptimizedImage } from '@angular/common';
512
import { AlertService } from '~core/services/ui/alert.service';
6-
import { catchError, of, switchMap } from 'rxjs';
7-
import { LetDirective, PushPipe } from '@ngrx/component';
13+
import { catchError, map, of, startWith, switchMap } from 'rxjs';
814
import { PokemonCardComponent } from '~features/user/my-pokemon/components/pokemon-card/pokemon-card.component';
915
import { translations } from '~locale/translations';
1016
import { PokemonSearchInputComponent } from '~shared/components/pokemon-search-input/pokemon-search-input.component';
1117

1218
@Component({
1319
selector: 'app-my-pokemon',
14-
imports: [
15-
PokemonCardComponent,
16-
NgOptimizedImage,
17-
PushPipe,
18-
LetDirective,
19-
PokemonSearchInputComponent,
20-
],
20+
imports: [PokemonCardComponent, NgOptimizedImage, PokemonSearchInputComponent],
2121
templateUrl: './my-pokemon.component.html',
2222
styleUrl: './my-pokemon.component.scss',
2323
changeDetection: ChangeDetectionStrategy.OnPush,
@@ -29,16 +29,26 @@ export class MyPokemonComponent {
2929
private readonly alertService = inject(AlertService);
3030

3131
readonly translations = translations;
32-
readonly userPokemons$ = this.userService.getMe({ cache: false }).pipe(
33-
switchMap((user) => {
34-
if (user.caughtPokemonIds.length === 0) {
32+
readonly loading = signal(true);
33+
34+
readonly userPokemons = toSignal(
35+
this.userService.getMe({ cache: false }).pipe(
36+
switchMap((user) => {
37+
if (user.caughtPokemonIds.length === 0) {
38+
return of([]);
39+
}
40+
return this.pokemonService.getPokemonByIds(user.caughtPokemonIds);
41+
}),
42+
catchError(() => {
43+
this.alertService.createErrorAlert(translations.genericErrorAlert);
3544
return of([]);
36-
}
37-
return this.pokemonService.getPokemonByIds(user.caughtPokemonIds);
38-
}),
39-
catchError(() => {
40-
this.alertService.createErrorAlert(translations.genericErrorAlert);
41-
return of([]);
42-
}),
45+
}),
46+
startWith([]),
47+
map((result) => {
48+
this.loading.set(false);
49+
return result;
50+
}),
51+
),
52+
{ initialValue: [] },
4353
);
4454
}

0 commit comments

Comments
 (0)