87 lines
2.4 KiB
C#
87 lines
2.4 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using Microsoft.EntityFrameworkCore.Metadata.Internal;
|
|
using Microsoft.JSInterop;
|
|
using Portfolio.Domain.Features.Pokemon;
|
|
|
|
namespace Portfolio.WebUI.Server.Components.Component.Pokemon_Components
|
|
{
|
|
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 void OnParametersSet()
|
|
{
|
|
if (AllPokemon != null) {
|
|
pokemons = AllPokemon.ToList();
|
|
|
|
foreach (var pokemon in pokemons)
|
|
{
|
|
isShiny[pokemon.Id] = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void ToggleImage(int Id)
|
|
{
|
|
if (isShiny.ContainsKey(Id))
|
|
{
|
|
isShiny[Id] = !isShiny[Id];
|
|
}
|
|
}
|
|
|
|
private bool ToggleVariationName(int Id, int PokemonId)
|
|
{
|
|
foreach (var pokemon in pokemons)
|
|
{
|
|
if (pokemon.PokemonId == PokemonId && pokemon.Id != Id)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
private async Task ConfirmDelete(int Id)
|
|
{
|
|
bool confirm = await JS.InvokeAsync<bool>("confirm", "Are you sure you want to delete this Pokémon?");
|
|
if (confirm)
|
|
{
|
|
await DeletePokemon(Id);
|
|
}
|
|
}
|
|
|
|
private async Task DeletePokemon(int Id)
|
|
{
|
|
await PokemonService.DeletePokemonAsync(Id);
|
|
pokemons.RemoveAll(p => p.Id == Id); // Remove from the list locally
|
|
StateHasChanged(); // Refresh the UI
|
|
}
|
|
|
|
private void EditPokemon(int id)
|
|
{
|
|
Navigation.NavigateTo($"/pokemonsleep/edit/{id}");
|
|
}
|
|
|
|
private void ViewPokemon(int id)
|
|
{
|
|
Navigation.NavigateTo($"/pokemon/{id}");
|
|
}
|
|
|
|
private string GetTypeImageUrl(string pokemonType)
|
|
{
|
|
if (string.IsNullOrEmpty(pokemonType))
|
|
{
|
|
return "https://www.serebii.net/pokemonsleep/pokemon/type/normal.png"; // Fallback image
|
|
}
|
|
|
|
return $"https://www.serebii.net/pokemonsleep/pokemon/type/{pokemonType.ToLower()}.png";
|
|
}
|
|
|
|
}
|
|
}
|