Browse Source

- Fix caught status updates

pull/1/head
Dan 1 year ago
parent
commit
a7c3a9ae4c
  1. 20
      src/app/core/services/pokemon.service.ts

20
src/app/core/services/pokemon.service.ts

@ -110,7 +110,7 @@ export class PokemonService {
Image: "", Image: "",
IsDefault: row.data.is_default || false, IsDefault: row.data.is_default || false,
IsGenderRelevant: row.data.gender_relevant, IsGenderRelevant: row.data.gender_relevant,
IsCaught: this.caughtPokemon.has(row.PFIC) IsCaught: this.caughtPokemon.has(row.pfic)
} as Pokemon; } as Pokemon;
pkmn.MarkIcon = this.getMarkImgName(pkmn.MarkName) pkmn.MarkIcon = this.getMarkImgName(pkmn.MarkName)
pkmn.Image = this.getPokemonImageUrl(pkmn) pkmn.Image = this.getPokemonImageUrl(pkmn)
@ -147,13 +147,12 @@ export class PokemonService {
} }
private updatePokemonCaughtStatus(pfic: string, isCaught: boolean) { private updatePokemonCaughtStatus(pfic: string, isCaught: boolean) {
this.pokemonGroups.forEach(group => { if(this.pokemonFormMap.has(pfic)) {
group.forEach(pokemon => { const pkmn = this.pokemonFormMap.get(pfic)
if (pokemon && pokemon.PFIC === pfic) { if (pkmn) {
pokemon.IsCaught = isCaught; pkmn.IsCaught = isCaught;
} }
}); }
});
} }
getCaughtPokemon(): Observable<string[]> { getCaughtPokemon(): Observable<string[]> {
@ -217,10 +216,7 @@ export class PokemonService {
this.getCaughtPokemon().subscribe( this.getCaughtPokemon().subscribe(
pfics => { pfics => {
pfics.forEach(pfic => this.updateCaughtStatus(pfic, true)); pfics.forEach(pfic => this.updateCaughtStatus(pfic, true));
// If pokemon are already loaded, update their status pfics.forEach(pfic => this.updatePokemonCaughtStatus(pfic, true));
if (this.pokemonGroups.length > 0) {
pfics.forEach(pfic => this.updatePokemonCaughtStatus(pfic, true));
}
} }
); );
} }

Loading…
Cancel
Save