From b8ca28e46fbe6f780e88858ec1addb0cbb8db57b Mon Sep 17 00:00:00 2001 From: BeatriceAl Date: Mon, 11 May 2026 23:41:08 +0200 Subject: [PATCH] Added filter to /list, potential change: live filter without seperate submit when onclick and oninput would work --- Guestlist/Components/Pages/GuestList.razor | 40 +++++++++++++++---- Guestlist/Components/Pages/GuestList.razor.cs | 29 ++++++++++++++ 2 files changed, 61 insertions(+), 8 deletions(-) diff --git a/Guestlist/Components/Pages/GuestList.razor b/Guestlist/Components/Pages/GuestList.razor index ac32ef4..825dac0 100644 --- a/Guestlist/Components/Pages/GuestList.razor +++ b/Guestlist/Components/Pages/GuestList.razor @@ -7,14 +7,30 @@

Read-only access for guests.

- @if (ShowLeaveGuestList) - { -
- +
+ + +
+ + + @if (!string.IsNullOrWhiteSpace(SearchTerm)) + { + Clear + } +
- } + + @if (ShowLeaveGuestList) + { +
+ +
+ } +
@if (GuestEntries is null) @@ -33,10 +49,18 @@ else if (GuestEntries.Count == 0) } +else if (!FilteredGuestEntries.Any()) +{ +
+
+

No guests match the current filter.

+
+
+} else {
- @foreach (var guest in GuestEntries) + @foreach (var guest in FilteredGuestEntries) {
diff --git a/Guestlist/Components/Pages/GuestList.razor.cs b/Guestlist/Components/Pages/GuestList.razor.cs index 48c1a83..63602dd 100644 --- a/Guestlist/Components/Pages/GuestList.razor.cs +++ b/Guestlist/Components/Pages/GuestList.razor.cs @@ -20,9 +20,38 @@ public partial class GuestList : ComponentBase protected List? GuestEntries { get; set; } protected bool ShowLeaveGuestList { get; set; } + protected string SearchTerm { get; set; } = ""; + + [SupplyParameterFromQuery(Name = "search")] + public string? IncomingSearchTerm { get; set; } + + protected IEnumerable 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 =