From 163a251579458213737f5bd12a2c257fcf63da43 Mon Sep 17 00:00:00 2001 From: Egamorf Date: Sun, 18 May 2025 16:59:30 +0200 Subject: [PATCH] fix select bugs --- .../Components/Search/SearchInput.razor | 1 + .../SelectSearch/SelectSearch.razor.cs | 28 ++++++++++++++++++- .../Constants/GlobalConstants.cs | 2 +- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Search/SearchInput.razor b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Search/SearchInput.razor index 410062d..9f9a6d3 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Search/SearchInput.razor +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Search/SearchInput.razor @@ -7,6 +7,7 @@ placeholder="@Placeholder" disabled="@IsDisable" style="@(IsDisable ? "pointer-events: none" : "")" + onClick="this.select();" @bind=@Text @bind:event="oninput" @bind:after="HandleTextChanged" diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/SelectSearch/SelectSearch.razor.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/SelectSearch/SelectSearch.razor.cs index 466d708..6613eba 100644 --- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/SelectSearch/SelectSearch.razor.cs +++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/SelectSearch/SelectSearch.razor.cs @@ -51,11 +51,37 @@ public partial class SelectSearch private async Task HandleClearClicked() { Values = []; - await ValuesChanged.InvokeAsync([.. Values]); + Select?.Close(); + SearchInput?.SetText(string.Empty); + await ValuesChanged.InvokeAsync([]); } private void HandleFocusIn() { Select?.Open(); } + private void HandleTextChanged(string args) + { + if (!string.IsNullOrEmpty(args)) + { + var keywords = args + .Split([' '], StringSplitOptions.RemoveEmptyEntries) + .Select(k => k.Trim()) + .ToArray() ?? []; + + SelectParams.Items = [.. Items + .Where(game => keywords.All( + kw => SelectParams.GetItemLabel(game).Contains(kw, StringComparison.OrdinalIgnoreCase) + )) + .OrderBy(game => keywords.Min(kw => + SelectParams.GetItemLabel(game).IndexOf(kw, StringComparison.OrdinalIgnoreCase) + )) + .ThenBy(game => SelectParams.GetItemLabel(game).Length)]; + } + else + { + SelectParams.Items = Items; + SearchInput?.SetText(string.Join(", ", Values?.Select(GetLabel) ?? [])); + } + } } \ No newline at end of file diff --git a/src/GameIdeas/GameIdeas.Shared/Constants/GlobalConstants.cs b/src/GameIdeas/GameIdeas.Shared/Constants/GlobalConstants.cs index 0620bdd..801c7cb 100644 --- a/src/GameIdeas/GameIdeas.Shared/Constants/GlobalConstants.cs +++ b/src/GameIdeas/GameIdeas.Shared/Constants/GlobalConstants.cs @@ -22,7 +22,7 @@ public class GlobalConstants public const int API_PORT = 8000; public const string SUB_DOMAIN_NAME = "api-"; - public const double DELAY_INPUT_MS = 500; + public const double DELAY_INPUT_MS = 450; public const int MAX_DESCRIPTION_LENGTH = 350; } -- 2.39.5