Skip to content

Commit

Permalink
Added basic Dweller searching
Browse files Browse the repository at this point in the history
  • Loading branch information
jake1164 committed Nov 16, 2024
1 parent 01a3079 commit 67b5513
Showing 1 changed file with 57 additions and 1 deletion.
58 changes: 57 additions & 1 deletion ShelterViewer/Pages/Dwellers.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@

<h3>Dwellers</h3>

<MudDataGrid T="Dweller" Items="DwellerList" Filterable="true" >
<MudDataGrid T="Dweller" Items="DwellerList" QuickFilter="@_quickFilter" Filterable="true" >
<ToolBarContent>
<MudText typo="Typo.h6">Dwellers</MudText>"
<MudSpacer />
<MudTextField @bind-Value="_searchString" Placeholder="Search" Adornment="Adornment.Start" Immediate="true"
AdornmentIcon="Icons.Material.Filled.Search" IconSize="Size.Medium" Class="mt-0"/>
</ToolBarContent>
<Columns>
<PropertyColumn Property="x => x.firstName" Title="First Name" />
<PropertyColumn Property="x => x.lastName" Title="Last Name" />
Expand Down Expand Up @@ -63,6 +69,8 @@
List<Dweller> DwellerList { get; set; } = new();
Dweller? selectedDweller;

private string _searchString = "";

protected override void OnInitialized()
{
if(VaultService.IsVaultEmpty())
Expand Down Expand Up @@ -91,4 +99,52 @@
var room = VaultService.GetRoom(roomNumber);
return room?.type ?? "Coffee Break";
}

private Func<Dweller, bool> _quickFilter => x =>
{
var intSearch = _searchString;
bool lt = false;
bool gt = false;
if (intSearch.StartsWith('<')){
lt = true;
intSearch = intSearch.Substring(((intSearch.StartsWith("<=")) ? 2 : 1));
}
if (intSearch.StartsWith('>')) {
gt = true;
intSearch = intSearch.Substring(((intSearch.StartsWith(">=")) ? 2 : 1));
}

if(int.TryParse(intSearch, out int n))
{
if(lt)
{
if (x.experience.currentLevel <= n)
return true;
return false;
}

if(gt)
{
if (x.experience.currentLevel >= n)
return true;
return false;
}

if (x.experience.currentLevel == n)
return true;

return false;
}

if (string.IsNullOrWhiteSpace(_searchString))
return true;

if (x.lastName.Contains(_searchString, StringComparison.OrdinalIgnoreCase))
return true;

if (x.firstName.Contains(_searchString, StringComparison.OrdinalIgnoreCase))
return true;

return false;
};
}

0 comments on commit 67b5513

Please sign in to comment.