From 54bdf901b805dc64ac50ccae736e734199522a38 Mon Sep 17 00:00:00 2001 From: sven-n Date: Fri, 17 Jul 2026 20:15:26 +0200 Subject: [PATCH] Merge pull request #833 from eduardosmaniotto/bugfix/account-search fix: account search typeahead not working (cherry picked from commit 8f2b32d5d3654d7ef3f271ba3e6a2ad19a2ff212) --- src/Web/AdminPanel/Pages/Accounts.razor | 5 ++- src/Web/Shared/Services/AccountService.cs | 38 +++++++++++++++++------ 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/Web/AdminPanel/Pages/Accounts.razor b/src/Web/AdminPanel/Pages/Accounts.razor index 81ab10a..c41ba94 100644 --- a/src/Web/AdminPanel/Pages/Accounts.razor +++ b/src/Web/AdminPanel/Pages/Accounts.razor @@ -22,13 +22,12 @@ @Resources.Action - +
- +
-
@item.LoginName diff --git a/src/Web/Shared/Services/AccountService.cs b/src/Web/Shared/Services/AccountService.cs index a4e5be9..9df8db1 100644 --- a/src/Web/Shared/Services/AccountService.cs +++ b/src/Web/Shared/Services/AccountService.cs @@ -6,19 +6,23 @@ namespace MUnique.OpenMU.Web.Shared.Services; using System.ComponentModel.DataAnnotations; using System.Diagnostics.CodeAnalysis; -using MUnique.OpenMU.Web.Shared.Components.Modal; using MUnique.OpenMU.DataModel.Entities; using MUnique.OpenMU.Persistence; +using MUnique.OpenMU.Web.Shared.Components; using MUnique.OpenMU.Web.Shared.Components.Form.Modal; +using MUnique.OpenMU.Web.Shared.Components.Modal; using MUnique.OpenMU.Web.Shared.Properties; /// /// Service for s. /// -public class AccountService : IDataService, ISupportDataChangedNotification +public class AccountService : IDataService, ISupportDataChangedNotification, IDisposable { private readonly IDataSource _dataSource; private readonly IModalService _modalService; + private readonly Debouncer _debouncer = new(300); + + private string _searchFilter = string.Empty; /// /// Initializes a new instance of the class. @@ -31,7 +35,8 @@ public class AccountService : IDataService, ISupportDataChangedNotifica this._modalService = modalService; } - private string _searchFilter = string.Empty; + /// + public event EventHandler? DataChanged; /// /// Gets or sets the search filter query. @@ -45,14 +50,19 @@ public class AccountService : IDataService, ISupportDataChangedNotifica if (this._searchFilter != newValue) { this._searchFilter = newValue; - this.RaiseDataChanged(); + if (string.IsNullOrEmpty(newValue)) + { + this._debouncer.Cancel(); + this.DataChanged?.Invoke(this, EventArgs.Empty); + } + else + { + _ = this._debouncer.DebounceAsync(this.RaiseDataChangedAsync); + } } } } - /// - public event EventHandler? DataChanged; - /// /// Returns a slice of the account list, defined by an offset and a count. /// @@ -138,11 +148,21 @@ public class AccountService : IDataService, ISupportDataChangedNotifica item.SecurityCode = accountParameters.SecurityCode; item.RegistrationDate = DateTime.UtcNow; await context.SaveChangesAsync().ConfigureAwait(false); - this.RaiseDataChanged(); + this.DataChanged?.Invoke(this, EventArgs.Empty); } } - private void RaiseDataChanged() => this.DataChanged?.Invoke(this, EventArgs.Empty); + /// + public void Dispose() + { + this._debouncer.Dispose(); + } + + private Task RaiseDataChangedAsync() + { + this.DataChanged?.Invoke(this, EventArgs.Empty); + return Task.CompletedTask; + } /// /// Parameters for the account creation which is used for the user interface.