TheShopCritics2/TSC2/Components/Pages/BrowseState.razor

112 lines
2.0 KiB
Plaintext

@page "/browse/{State}"
@using TSC2.Components.CSharp;
<title>@State | The Shop Critics</title>
<body>
@if (isValid)
{
<h1>@State</h1>
<h2>@results</h2>
<ul>
@foreach (Tuple<string, string, string, float> current in filterResults)
{
<li><a href="/info/@current.Item2&@current.Item1">@current.Item4 * | @current.Item2 | @current.Item3</a></li>
}
</ul>
}
else
{
<h1>Invalid state.</h1>
}
</body>
@code {
[Parameter]
public string State { get; set; } = "MI";
private string results = "No results found.";
private List<Tuple<string,string,string,float>> filterResults = new();
private bool isValid = false;
protected override Task OnInitializedAsync()
{
// Verify that the requested url is valid
var states = Enum.GetValues(typeof(States)).Cast<States>().ToList();
if (Enum.IsDefined(typeof(States), State))
{
// If a valid state, let it filter
isValid = true;
filterResults = DatabaseManager.FilterByState(State);
if (filterResults.Count == 0)
return Task.FromResult(0);
this.results = "Results:\n";
}
else
{
isValid = false;
}
return Task.FromResult(0);
}
private enum States
{
AL,
AK,
AR,
AZ,
CA,
CO,
CT,
DC,
DE,
FL,
GA,
HI,
IA,
ID,
IL,
IN,
KS,
KY,
LA,
MA,
MD,
ME,
MI,
MN,
MO,
MS,
MT,
NC,
ND,
NE,
NH,
NJ,
NM,
NV,
NY,
OK,
OH,
OR,
PA,
RI,
SC,
SD,
TN,
TX,
UT,
VA,
VT,
WA,
WI,
WV,
WY
}
}