-
-
+
\ No newline at end of file
diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Search/SearchInput.razor.cs b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Search/SearchInput.razor.cs
index fd0f42e..97a2e29 100644
--- a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Search/SearchInput.razor.cs
+++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Search/SearchInput.razor.cs
@@ -1,11 +1,13 @@
using GameIdeas.BlazorApp.Shared.Constants;
using GameIdeas.Shared.Constants;
using Microsoft.AspNetCore.Components;
+using Microsoft.JSInterop;
namespace GameIdeas.BlazorApp.Shared.Components.Search;
public partial class SearchInput
{
+ [Inject] private IJSRuntime Js { get; set; } = default!;
[Parameter] public string? Text { get; set; }
[Parameter] public string? Placeholder { get; set; }
[Parameter] public bool IsDisable { get; set; }
@@ -17,17 +19,20 @@ public partial class SearchInput
private ElementReference InputText;
- protected override void OnInitialized()
+ protected override async Task OnAfterRenderAsync(bool firstRender)
{
Text = string.Empty;
+ await Js.InvokeVoidAsync("addStopWriteListener", DotNetObjectReference.Create(this));
+ await base.OnAfterRenderAsync(firstRender);
}
public void SetText(string str)
{
Text = str;
}
-
- private async Task HandleTextChanged()
+
+ [JSInvokable]
+ public async Task HandleTextEnd()
{
await TextChanged.InvokeAsync(Text);
}
diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Search/SearchInput.razor.js b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Search/SearchInput.razor.js
new file mode 100644
index 0000000..d9ba0d9
--- /dev/null
+++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/Shared/Components/Search/SearchInput.razor.js
@@ -0,0 +1,19 @@
+function debounce(func, delay, dotNetReference) {
+ let timeoutId;
+ return function () {
+ clearTimeout(timeoutId);
+ timeoutId = setTimeout(() => {
+ func.apply(this, dotNetReference);
+ }, delay);
+ };
+}
+
+function handleInputStop(dotNetReference) {
+ console.log("L'utilisateur a arrêté de taper.");
+ //dotNetReference.invokeMethodAsync("HandleTextEnd");
+}
+
+function addStopWriteListener(dotNetReference) {
+ const input = document.getElementById('searchInput');
+ input.addEventListener('input', debounce(handleInputStop, 1000, dotNetReference)); // 500ms après la dernière frappe
+}
\ No newline at end of file
diff --git a/src/GameIdeas/Client/GameIdeas.BlazorApp/wwwroot/index.html b/src/GameIdeas/Client/GameIdeas.BlazorApp/wwwroot/index.html
index bc8684e..2b4ad65 100644
--- a/src/GameIdeas/Client/GameIdeas.BlazorApp/wwwroot/index.html
+++ b/src/GameIdeas/Client/GameIdeas.BlazorApp/wwwroot/index.html
@@ -27,7 +27,7 @@
-
+