Added filter to /list, potential change: live filter without seperate submit when onclick and oninput would work
This commit is contained in:
@@ -7,14 +7,30 @@
|
||||
<p class="text-secondary mb-0">Read-only access for guests.</p>
|
||||
</div>
|
||||
|
||||
<div class="d-flex flex-column flex-sm-row gap-3 w-100 w-md-auto">
|
||||
<form method="get" action="/list" class="w-100 w-md-auto">
|
||||
<label class="form-label" for="guest-list-search">Search</label>
|
||||
<div class="d-flex gap-2">
|
||||
<input id="guest-list-search" class="form-control" name="search" value="@SearchTerm" placeholder="Name, note or user" />
|
||||
<button type="submit" class="btn btn-outline-primary">
|
||||
Search
|
||||
</button>
|
||||
@if (!string.IsNullOrWhiteSpace(SearchTerm))
|
||||
{
|
||||
<a class="btn btn-outline-secondary" href="/list">Clear</a>
|
||||
}
|
||||
</div>
|
||||
</form>
|
||||
|
||||
@if (ShowLeaveGuestList)
|
||||
{
|
||||
<form method="post" action="/guest/logout">
|
||||
<form method="post" action="/guest/logout" class="align-self-sm-end">
|
||||
<button type="submit" class="btn btn-outline-secondary">
|
||||
Leave guest list
|
||||
</button>
|
||||
</form>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@if (GuestEntries is null)
|
||||
@@ -33,10 +49,18 @@ else if (GuestEntries.Count == 0)
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else if (!FilteredGuestEntries.Any())
|
||||
{
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<p class="text-secondary mb-0">No guests match the current filter.</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
else
|
||||
{
|
||||
<div class="guest-card-grid">
|
||||
@foreach (var guest in GuestEntries)
|
||||
@foreach (var guest in FilteredGuestEntries)
|
||||
{
|
||||
<article class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
|
||||
@@ -20,9 +20,38 @@ public partial class GuestList : ComponentBase
|
||||
|
||||
protected List<GuestEntryDocument>? GuestEntries { get; set; }
|
||||
protected bool ShowLeaveGuestList { get; set; }
|
||||
protected string SearchTerm { get; set; } = "";
|
||||
|
||||
[SupplyParameterFromQuery(Name = "search")]
|
||||
public string? IncomingSearchTerm { get; set; }
|
||||
|
||||
protected IEnumerable<GuestEntryDocument> FilteredGuestEntries
|
||||
{
|
||||
get
|
||||
{
|
||||
if (GuestEntries is null)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(SearchTerm))
|
||||
{
|
||||
return GuestEntries;
|
||||
}
|
||||
|
||||
var searchTerm = SearchTerm.Trim();
|
||||
|
||||
return GuestEntries.Where(guest =>
|
||||
guest.Name.Contains(searchTerm, StringComparison.OrdinalIgnoreCase) ||
|
||||
(guest.Notes?.Contains(searchTerm, StringComparison.OrdinalIgnoreCase) == true) ||
|
||||
guest.AddedByUsername.Contains(searchTerm, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
SearchTerm = IncomingSearchTerm ?? "";
|
||||
|
||||
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
||||
var user = authState.User;
|
||||
var isStaffUser =
|
||||
|
||||
Reference in New Issue
Block a user