Skip to content

Commit

Permalink
Start work on #67, move PokeRus logic to own component
Browse files Browse the repository at this point in the history
  • Loading branch information
codemonkey85 committed Nov 23, 2024
1 parent d9b4d95 commit 73306ad
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 10 deletions.
11 changes: 1 addition & 10 deletions Pkmds.Web/Components/EditForms/Tabs/MainTab.razor
Original file line number Diff line number Diff line change
Expand Up @@ -300,16 +300,7 @@ AppState.SelectedSlotsAreValid)
@bind-Value:after="@RefreshService.Refresh"
For="@(() => Pokemon.IsEgg)" />

<MudCheckBox Label="Infected"
@bind-Value="@Pokemon.IsPokerusInfected"
@bind-Value:after="@RefreshService.Refresh"
For="@(() => Pokemon.IsPokerusInfected)" />

<MudCheckBox Label="Cured"
@bind-Value="@Pokemon.IsPokerusCured"
@bind-Value:after="@RefreshService.Refresh"
For="@(() => Pokemon.IsPokerusCured)" />

<PokerusComponent Pokemon="Pokemon" />
}

@if (Pokemon is PK5 pk5)
Expand Down
42 changes: 42 additions & 0 deletions Pkmds.Web/Components/EditForms/Tabs/PokerusComponent.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
@if (Pokemon is { } pokemon)
{
<MudCheckBox Label="Infected"
@bind-Value:get="@pokemon.IsPokerusInfected"
@bind-Value:set="@((bool infected) => SetPokerusInfected(infected))"
For="@(() => pokemon.IsPokerusInfected)" />

<MudCheckBox Label="Cured"
@bind-Value:get="@pokemon.IsPokerusCured"
@bind-Value:set="@((bool cured) => SetPokerusCured(cured))"
For="@(() => pokemon.IsPokerusCured)" />

@if (pokemon.IsPokerusInfected)
{
<MudSelect Label="Strain"
@bind-Value:get="@pokemon.PokerusStrain"
@bind-Value:set="@((int strain) => SetPokerusStrain(strain))">
@for (var i = 0; i < 16; i++)
{
<MudSelectItem Value="@i"
@key="@i">
@i
</MudSelectItem>
}
</MudSelect>

@if (!pokemon.IsPokerusCured)
{
<MudSelect Label="Days"
@bind-Value:get="@pokemon.PokerusDays"
@bind-Value:set="@((int days) => SetPokerusDays(days))">
@for (var i = 0; i < 3; i++)
{
<MudSelectItem Value="@i"
@key="@i">
@i
</MudSelectItem>
}
</MudSelect>
}
}
}
46 changes: 46 additions & 0 deletions Pkmds.Web/Components/EditForms/Tabs/PokerusComponent.razor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
namespace Pkmds.Web.Components.EditForms.Tabs;

public partial class PokerusComponent
{
[Parameter, EditorRequired]
public PKM? Pokemon { get; set; }

private void SetPokerusInfected(bool infected)
{
if (Pokemon is null)
{
return;
}

Pokemon.IsPokerusInfected = infected;
}

private void SetPokerusCured(bool cured)
{
if (Pokemon is null)
{
return;
}

Pokemon.IsPokerusCured = cured;
}

private void SetPokerusStrain(int strain)
{
if (Pokemon is null)
{
return;
}
Pokemon.PokerusStrain = strain;
}

private void SetPokerusDays(int days)
{
if (Pokemon is null)
{
return;
}
Pokemon.PokerusDays = days;
}
}

0 comments on commit 73306ad

Please sign in to comment.