mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-08-20 16:32:57 +00:00
Fix debounce timer setup and synchronization logic in DebouncedTextField component
This commit is contained in:
parent
29694e7edb
commit
0fa2e91afc
@ -51,6 +51,7 @@ public partial class DebouncedTextField : MudComponentBase, IDisposable
|
|||||||
private readonly Timer debounceTimer = new();
|
private readonly Timer debounceTimer = new();
|
||||||
private string text = string.Empty;
|
private string text = string.Empty;
|
||||||
private string lastParameterText = string.Empty;
|
private string lastParameterText = string.Empty;
|
||||||
|
private bool isInitialized;
|
||||||
|
|
||||||
#region Overrides of ComponentBase
|
#region Overrides of ComponentBase
|
||||||
|
|
||||||
@ -68,21 +69,29 @@ public partial class DebouncedTextField : MudComponentBase, IDisposable
|
|||||||
this.InvokeAsync(() => this.WhenTextCanged(this.text));
|
this.InvokeAsync(() => this.WhenTextCanged(this.text));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.isInitialized = true;
|
||||||
await base.OnInitializedAsync();
|
await base.OnInitializedAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task OnParametersSetAsync()
|
protected override async Task OnParametersSetAsync()
|
||||||
{
|
{
|
||||||
|
// Ensure the timer uses the latest debouncing interval:
|
||||||
|
if (!this.isInitialized)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if(Math.Abs(this.debounceTimer.Interval - this.DebounceTime.TotalMilliseconds) > 1)
|
||||||
|
this.debounceTimer.Interval = this.DebounceTime.TotalMilliseconds;
|
||||||
|
|
||||||
// Only sync when the parent's parameter actually changed since the last change:
|
// Only sync when the parent's parameter actually changed since the last change:
|
||||||
if (this.Text != this.lastParameterText)
|
if (this.Text != this.lastParameterText)
|
||||||
{
|
{
|
||||||
this.text = this.Text;
|
this.text = this.Text;
|
||||||
this.lastParameterText = this.Text;
|
this.lastParameterText = this.Text;
|
||||||
|
|
||||||
this.debounceTimer.Stop();
|
|
||||||
this.debounceTimer.Start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.debounceTimer.Stop();
|
||||||
|
this.debounceTimer.Start();
|
||||||
|
|
||||||
await base.OnParametersSetAsync();
|
await base.OnParametersSetAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user