From 2a01c2fae2affacbd5751c8499e84ad841732ba7 Mon Sep 17 00:00:00 2001 From: Kira Jiroux Date: Fri, 7 Mar 2025 13:42:09 -0500 Subject: [PATCH] Became more of a searchable field with viewable dropdown options, but I'm happy with it. --- .../Components/Pages/PokemonRate.razor | 455 ++++++------------ .../Components/Pages/PokemonRate.razor.cs | 173 +++++++ .../Components/_Imports.razor | 3 +- 3 files changed, 314 insertions(+), 317 deletions(-) create mode 100644 Portfolio.WebUI.Server/Components/Pages/PokemonRate.razor.cs diff --git a/Portfolio.WebUI.Server/Components/Pages/PokemonRate.razor b/Portfolio.WebUI.Server/Components/Pages/PokemonRate.razor index bb63b9d..5c78543 100644 --- a/Portfolio.WebUI.Server/Components/Pages/PokemonRate.razor +++ b/Portfolio.WebUI.Server/Components/Pages/PokemonRate.razor @@ -8,7 +8,6 @@ @attribute [StreamRendering] @rendermode InteractiveServer - Rate Pokémon
@@ -19,333 +18,159 @@
- @if (PokemonList == null || NatureList == null || SubskillList == null) {

Loading...

} else { -
+
-
-
-
+
+
+

Pokémon Rater

-
- - -
-
-
- - -
-
- - - @if (SelectedPokemon != null) - { -
-
- - -
- - - @if (SelectedPokemon.IsVariation) - { -
-
- - - -
-
- } - else - { -
-
- - - -
-
- } -
-
- -
- @if (SelectedPokemon.IsVariation) // If a Variant - { -

@SelectedPokemon.VariationName @SelectedPokemon.PokemonName

- } - else // Otherwise, Base Case - { -

@SelectedPokemon.PokemonName

- } -
- - -
-

Pokédex #@SelectedPokemon.PokemonId

-
- - -
- - -
-
-

@SelectedPokemon.SleepType

- -

@SelectedPokemon.Speciality

- -
- -
-
- -
- - - - -
-

Select Nature & Subskills

- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- -
- -
- - - -
- -

Final Score: @FinalScore

-
- - -
- } -
-} +
+ +
+
+
+ + @if (FilteredPokemonList.Any() && !string.IsNullOrWhiteSpace(PokemonSearchTerm)) + { +
    + @foreach (var pokemon in FilteredPokemonList) + { +
  • + @if (pokemon.IsVariation) + { + @($"{pokemon.PokemonId} {pokemon.VariationName} {pokemon.PokemonName}") + } + else + { + @($"{pokemon.PokemonId} {pokemon.PokemonName}") + } +
  • + } +
+ } +
+
+
- -@code { - - private List PokemonList; - private List NatureList; - private List SubskillList; - - private Dictionary isShiny = new Dictionary(); - - - private int _selectedPokemonId; - private int SelectedPokemonId - { - get => _selectedPokemonId; - set - { - _selectedPokemonId = value; - OnPokemonSelected(); - } - } - - private int SelectedNatureId; - private int subskillSelect1; - private int subskillSelect2; - private int subskillSelect3; - - private int[] SelectedSubskills = new int[3]; - - private Pokemon SelectedPokemon; - - private int FinalScore; - private string ScoreBackgroundColor; - private string ScoreColor; - - private string PokemonImageUrl => SelectedPokemon != null - ? $"https://www.serebii.net/pokemonsleep/pokemon/{SelectedPokemon.Id}.png" - : string.Empty; - - protected override async Task OnInitializedAsync() - { - PokemonList = await PokemonService.GetAllPokemonAsync(); - NatureList = await PokemonNatureService.GetAllPokemonNaturesAsync(); - SubskillList = await PokemonSubskillService.GetAllPokemonSubskillsAsync(); - - if (PokemonList is not null) - { - - PokemonList.Sort((x, y) => x.PokemonId.CompareTo(y.PokemonId)); - - // Initialize dictionary with false (show base image first) - foreach (var pokemon in PokemonList) + + @if (SelectedPokemon != null) { - isShiny[pokemon.Id] = false; +
+
+ +
+ +
+
+ + +
+
+
+
+
+ @if (SelectedPokemon.IsVariation) + { +

@SelectedPokemon.VariationName @SelectedPokemon.PokemonName

+ } + else + { +

@SelectedPokemon.PokemonName

+ } +
+
+

Pokédex #@SelectedPokemon.PokemonId

+
+
+ +
+
+

@SelectedPokemon.SleepType

+

@SelectedPokemon.Speciality

+
+
+
+ +
+ + +
+

Select Nature & Subskills

+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ +
+ +
+ + +
+ +

Final Score: @FinalScore

+
+
} - - } - - } - - private async void OnPokemonSelected() - { - if (SelectedPokemonId > 0) - { - SelectedPokemon = await PokemonService.GetPokemonByIdAsync(SelectedPokemonId); - StateHasChanged(); // Force UI to refresh - } - } - - private void ToggleImage(int Id) - { - if (isShiny.ContainsKey(Id)) - { - isShiny[Id] = !isShiny[Id]; - } - } - - private void CalculateScore() - { - if (SelectedPokemon == null || SelectedNatureId == 0 || subskillSelect1 == 0 || subskillSelect2 == 0 || subskillSelect3 == 0 ) - { - return; - } - - var nature = NatureList.FirstOrDefault(n => n.Id == SelectedNatureId); - var subskill1 = SubskillList.FirstOrDefault(s => s.Id == subskillSelect1); - var subskill2 = SubskillList.FirstOrDefault(s => s.Id == subskillSelect2); - var subskill3 = SubskillList.FirstOrDefault(s => s.Id == subskillSelect3); - - if (nature == null || subskill1 == null || subskill2 == null || subskill3 == null) - { - return; - } - - FinalScore = SelectedPokemon.Speciality switch - { - "Berries" => nature.BerryRating + subskill1.BerryRank + subskill2.BerryRank + subskill3.BerryRank, - "Ingredients" => nature.IngredientRating + subskill1.IngredientRank + subskill2.IngredientRank + subskill3.IngredientRank, - "Skills" => nature.SkillRating + subskill1.SkillRank + subskill2.SkillRank + subskill3.SkillRank, - _ => 0 - }; - - ScoreBackgroundColor = FinalScore switch - { - 8 => "#16C47F", - 7 => "#33CB8F", - 6 => "#50D39F", - 5 => "#6DDAAF", - 4 => "#8BE2BF", - 3 => "#A8E9CF", - 2 => "#C5F0DF", - 1 => "#E2F8EF", - 0 => "#FFFFFF", - -1 => "#FFE7E7", - -2 => "#FED0D0", - -3 => "#FEB8B8", - -4 => "#FDA0A0", - -5 => "#FD8888", - -6 => "#FC7171", - -7 => "#FC5959", - -8 => "#FB4141", - _ => "#FFFFFF" - - }; - ScoreColor = FinalScore switch - { - 8 => "#FFFFFF", - 7 => "#FFFFFF", - 6 => "#FFFFFF", - 5 => "#FFFFFF", - 4 => "#FFFFFF", - 3 => "#FFFFFF", - 2 => "#FFFFFF", - 1 => "#FFFFFF", - 0 => "#000", - -1 => "#FFFFFF", - -2 => "#FFFFFF", - -3 => "#FFFFFF", - -4 => "#FFFFFF", - -5 => "#FFFFFF", - -6 => "#FFFFFF", - -7 => "#FFFFFF", - -8 => "#FFFFFF", - _ => "#FFFFFF" - - }; - } - - -} \ No newline at end of file +
+
+} diff --git a/Portfolio.WebUI.Server/Components/Pages/PokemonRate.razor.cs b/Portfolio.WebUI.Server/Components/Pages/PokemonRate.razor.cs new file mode 100644 index 0000000..18ee694 --- /dev/null +++ b/Portfolio.WebUI.Server/Components/Pages/PokemonRate.razor.cs @@ -0,0 +1,173 @@ +using Microsoft.AspNetCore.Components; +using Portfolio.Domain.Features.Pokemon; +using Portfolio.Domain.Features.Pokemon_Natures; +using Portfolio.Domain.Features.Pokemon_Subskills; + +namespace Portfolio.WebUI.Server.Components.Pages +{ + public partial class PokemonRate + { + private List PokemonList; + private List NatureList; + private List SubskillList; + + private Dictionary isShiny = new Dictionary(); + + private int _selectedPokemonId; + private int SelectedPokemonId + { + get => _selectedPokemonId; + set + { + _selectedPokemonId = value; + OnPokemonSelected(); + } + } + + private int SelectedNatureId; + private int subskillSelect1; + private int subskillSelect2; + private int subskillSelect3; + + private int[] SelectedSubskills = new int[3]; + + private Pokemon SelectedPokemon; + + private int FinalScore; + private string ScoreBackgroundColor; + private string ScoreColor; + + private string PokemonImageUrl => SelectedPokemon != null + ? $"https://www.serebii.net/pokemonsleep/pokemon/{SelectedPokemon.Id}.png" + : string.Empty; + + private string PokemonSearchTerm = string.Empty; + + // Filter Pokémon based on the search input term + private List FilteredPokemonList => string.IsNullOrWhiteSpace(PokemonSearchTerm) + ? PokemonList + : PokemonList.Where(p => p.PokemonName.Contains(PokemonSearchTerm, StringComparison.OrdinalIgnoreCase)).ToList(); + + private async Task OnSearchTextChanged(ChangeEventArgs e) + { + // Trigger filtering as the user types + PokemonSearchTerm = e.Value.ToString(); + } + + private async Task SelectPokemon(Pokemon pokemon) + { + SelectedPokemon = pokemon; + PokemonSearchTerm = string.Empty; // Reset search term + FilteredPokemonList.Clear(); // Clear the filtered list to hide dropdown + } + + private async void OnPokemonSelected() + { + if (SelectedPokemonId > 0) + { + SelectedPokemon = await PokemonService.GetPokemonByIdAsync(SelectedPokemonId); + StateHasChanged(); // Force UI to refresh + } + } + + private void CalculateScore() + { + if (SelectedPokemon == null || SelectedNatureId == 0 || subskillSelect1 == 0 || subskillSelect2 == 0 || subskillSelect3 == 0) + { + return; + } + + var nature = NatureList.FirstOrDefault(n => n.Id == SelectedNatureId); + var subskill1 = SubskillList.FirstOrDefault(s => s.Id == subskillSelect1); + var subskill2 = SubskillList.FirstOrDefault(s => s.Id == subskillSelect2); + var subskill3 = SubskillList.FirstOrDefault(s => s.Id == subskillSelect3); + + if (nature == null || subskill1 == null || subskill2 == null || subskill3 == null) + { + return; + } + + FinalScore = SelectedPokemon.Speciality switch + { + "Berries" => nature.BerryRating + subskill1.BerryRank + subskill2.BerryRank + subskill3.BerryRank, + "Ingredients" => nature.IngredientRating + subskill1.IngredientRank + subskill2.IngredientRank + subskill3.IngredientRank, + "Skills" => nature.SkillRating + subskill1.SkillRank + subskill2.SkillRank + subskill3.SkillRank, + _ => 0 + }; + + ScoreBackgroundColor = FinalScore switch + { + 8 => "#16C47F", + 7 => "#33CB8F", + 6 => "#50D39F", + 5 => "#6DDAAF", + 4 => "#8BE2BF", + 3 => "#A8E9CF", + 2 => "#C5F0DF", + 1 => "#E2F8EF", + 0 => "#FFFFFF", + -1 => "#FFE7E7", + -2 => "#FED0D0", + -3 => "#FEB8B8", + -4 => "#FDA0A0", + -5 => "#FD8888", + -6 => "#FC7171", + -7 => "#FC5959", + -8 => "#FB4141", + _ => "#FFFFFF" + + }; + ScoreColor = FinalScore switch + { + 8 => "#FFFFFF", + 7 => "#FFFFFF", + 6 => "#FFFFFF", + 5 => "#FFFFFF", + 4 => "#FFFFFF", + 3 => "#FFFFFF", + 2 => "#FFFFFF", + 1 => "#FFFFFF", + 0 => "#000", + -1 => "#FFFFFF", + -2 => "#FFFFFF", + -3 => "#FFFFFF", + -4 => "#FFFFFF", + -5 => "#FFFFFF", + -6 => "#FFFFFF", + -7 => "#FFFFFF", + -8 => "#FFFFFF", + _ => "#FFFFFF" + + }; + } + + protected override async Task OnInitializedAsync() + { + PokemonList = await PokemonService.GetAllPokemonAsync(); + NatureList = await PokemonNatureService.GetAllPokemonNaturesAsync(); + SubskillList = await PokemonSubskillService.GetAllPokemonSubskillsAsync(); + + if (PokemonList is not null) + { + + PokemonList.Sort((x, y) => x.PokemonId.CompareTo(y.PokemonId)); + + // Initialize dictionary with false (show base image first) + foreach (var pokemon in PokemonList) + { + isShiny[pokemon.Id] = false; + } + + } + + } + + private void ToggleImage(int Id) + { + if (isShiny.ContainsKey(Id)) + { + isShiny[Id] = !isShiny[Id]; + } + } + } +} diff --git a/Portfolio.WebUI.Server/Components/_Imports.razor b/Portfolio.WebUI.Server/Components/_Imports.razor index bb6b624..d534da2 100644 --- a/Portfolio.WebUI.Server/Components/_Imports.razor +++ b/Portfolio.WebUI.Server/Components/_Imports.razor @@ -16,5 +16,4 @@ @using Portfolio.Application.Services.Articles @using Portfolio.Application.Services.PokemonService @using Portfolio.Application.Services.PokemonNatureService -@using Portfolio.Application.Services.PokemonSubskillService - +@using Portfolio.Application.Services.PokemonSubskillService \ No newline at end of file