Data being passed from PokemonSleep parent to PokemonTable child. Getting ready for PokemonBackground!

This commit is contained in:
Kira Jiroux 2025-03-28 15:33:13 -04:00
parent 2e1063c741
commit b6b4be9dbb
4 changed files with 40 additions and 9 deletions

View File

@ -0,0 +1,6 @@
namespace Portfolio.WebUI.Server.Components.Component
{
public partial class PokemonBackground
{
}
}

View File

@ -1,4 +1,5 @@
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.AspNetCore.Components;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.JSInterop;
using Portfolio.Domain.Features.Pokemon;
@ -6,19 +7,18 @@ namespace Portfolio.WebUI.Server.Components.Component
{
public partial class PokemonTable
{
[Parameter]
public List<Pokemon> AllPokemon { get; set; }
private List<Pokemon> pokemons = new List<Pokemon>();
private Dictionary<int, bool> isShiny = new Dictionary<int, bool>();
protected override async Task OnInitializedAsync()
protected override void OnParametersSet()
{
var result = await PokemonService.GetAllPokemonAsync();
if (result is not null)
{
pokemons = result;
pokemons.Sort((x, y) => x.PokemonId.CompareTo(y.PokemonId));
if (AllPokemon != null) {
pokemons = AllPokemon.ToList();
// Initialize dictionary with false (show base image first)
foreach (var pokemon in pokemons)
{
isShiny[pokemon.Id] = false;

View File

@ -1,5 +1,7 @@
@page "/pokemonsleep"
@inject IPokemonService PokemonService
@attribute [StreamRendering]
@rendermode InteractiveServer
@ -11,6 +13,6 @@
<PokemonHeader />
<PokemonTable />
<PokemonTable AllPokemon="pokemons"/>
</div>

View File

@ -0,0 +1,23 @@
using Portfolio.Application.Services.PokemonService;
using Portfolio.Domain.Features.Pokemon;
namespace Portfolio.WebUI.Server.Components.Pages
{
public partial class PokemonSleep
{
public List<Pokemon> pokemons = new List<Pokemon>();
protected override async Task OnInitializedAsync()
{
var result = await PokemonService.GetAllPokemonAsync();
if (result is not null)
{
pokemons = result;
pokemons.Sort((x, y) => x.PokemonId.CompareTo(y.PokemonId));
}
}
}
}