Merge pull request #833 from eduardosmaniotto/bugfix/account-search
fix: account search typeahead not working (cherry picked from commit 8f2b32d5d3654d7ef3f271ba3e6a2ad19a2ff212)
This commit is contained in:
@@ -22,13 +22,12 @@
|
|||||||
<th class="col-2">@Resources.Action</th>
|
<th class="col-2">@Resources.Action</th>
|
||||||
</TableHeader>
|
</TableHeader>
|
||||||
<FilterHeader>
|
<FilterHeader>
|
||||||
<th colspan="3">
|
<th colspan="4">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<span class="input-group-text"><span class="oi oi-magnifying-glass" aria-hidden="true"></span></span>
|
<span class="input-group-text"><span class="oi oi-magnifying-glass" aria-hidden="true"></span></span>
|
||||||
<input type="search" class="form-control" placeholder="Search by Account or Character Name..." @bind="@this._accountService.SearchFilter"/>
|
<input class="form-control small" type="search" autofocus @bind="@this._accountService.SearchFilter" @bind:event="oninput" placeholder="@Resources.Search ..."/>
|
||||||
</div>
|
</div>
|
||||||
</th>
|
</th>
|
||||||
<th></th>
|
|
||||||
</FilterHeader>
|
</FilterHeader>
|
||||||
<ItemTemplate Context="item">
|
<ItemTemplate Context="item">
|
||||||
<td>@item.LoginName</td>
|
<td>@item.LoginName</td>
|
||||||
|
|||||||
@@ -6,19 +6,23 @@ namespace MUnique.OpenMU.Web.Shared.Services;
|
|||||||
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
using System.ComponentModel.DataAnnotations;
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using MUnique.OpenMU.Web.Shared.Components.Modal;
|
|
||||||
using MUnique.OpenMU.DataModel.Entities;
|
using MUnique.OpenMU.DataModel.Entities;
|
||||||
using MUnique.OpenMU.Persistence;
|
using MUnique.OpenMU.Persistence;
|
||||||
|
using MUnique.OpenMU.Web.Shared.Components;
|
||||||
using MUnique.OpenMU.Web.Shared.Components.Form.Modal;
|
using MUnique.OpenMU.Web.Shared.Components.Form.Modal;
|
||||||
|
using MUnique.OpenMU.Web.Shared.Components.Modal;
|
||||||
using MUnique.OpenMU.Web.Shared.Properties;
|
using MUnique.OpenMU.Web.Shared.Properties;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Service for <see cref="Account"/>s.
|
/// Service for <see cref="Account"/>s.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class AccountService : IDataService<Account>, ISupportDataChangedNotification
|
public class AccountService : IDataService<Account>, ISupportDataChangedNotification, IDisposable
|
||||||
{
|
{
|
||||||
private readonly IDataSource<Account> _dataSource;
|
private readonly IDataSource<Account> _dataSource;
|
||||||
private readonly IModalService _modalService;
|
private readonly IModalService _modalService;
|
||||||
|
private readonly Debouncer _debouncer = new(300);
|
||||||
|
|
||||||
|
private string _searchFilter = string.Empty;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="AccountService"/> class.
|
/// Initializes a new instance of the <see cref="AccountService"/> class.
|
||||||
@@ -31,7 +35,8 @@ public class AccountService : IDataService<Account>, ISupportDataChangedNotifica
|
|||||||
this._modalService = modalService;
|
this._modalService = modalService;
|
||||||
}
|
}
|
||||||
|
|
||||||
private string _searchFilter = string.Empty;
|
/// <inheritdoc />
|
||||||
|
public event EventHandler? DataChanged;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the search filter query.
|
/// Gets or sets the search filter query.
|
||||||
@@ -45,14 +50,19 @@ public class AccountService : IDataService<Account>, ISupportDataChangedNotifica
|
|||||||
if (this._searchFilter != newValue)
|
if (this._searchFilter != newValue)
|
||||||
{
|
{
|
||||||
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public event EventHandler? DataChanged;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a slice of the account list, defined by an offset and a count.
|
/// Returns a slice of the account list, defined by an offset and a count.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -138,11 +148,21 @@ public class AccountService : IDataService<Account>, ISupportDataChangedNotifica
|
|||||||
item.SecurityCode = accountParameters.SecurityCode;
|
item.SecurityCode = accountParameters.SecurityCode;
|
||||||
item.RegistrationDate = DateTime.UtcNow;
|
item.RegistrationDate = DateTime.UtcNow;
|
||||||
await context.SaveChangesAsync().ConfigureAwait(false);
|
await context.SaveChangesAsync().ConfigureAwait(false);
|
||||||
this.RaiseDataChanged();
|
this.DataChanged?.Invoke(this, EventArgs.Empty);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RaiseDataChanged() => this.DataChanged?.Invoke(this, EventArgs.Empty);
|
/// <inheritdoc />
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
this._debouncer.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Task RaiseDataChangedAsync()
|
||||||
|
{
|
||||||
|
this.DataChanged?.Invoke(this, EventArgs.Empty);
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parameters for the account creation which is used for the user interface.
|
/// Parameters for the account creation which is used for the user interface.
|
||||||
|
|||||||
Reference in New Issue
Block a user