4 changed files
WPE.App.Shared.BaseComponents | ||
Data | ||
DelayedCallHelper.cs + | ||
InputHelper.cs + | ||
Pages/ActionElement/Searchbar | ||
SearchbarPeople.razor | ||
WPE.App.Shared.BaseComponents.csproj | ||
DelayedCallHelper.cs
/WPE.App.Shared.BaseComponents/Data/DelayedCallHelper.cs+36/WPE.App.Shared.BaseComponents/Data/DelayedCallHelper.cs
Add comment 1 Plus namespace WPE.App.Shared.BaseComponents.Data
Add comment 2 Plus {
Add comment 3 Plus public class DelayedCallHelper<T>
Add comment 4 Plus {
Add comment 5 Plus private DateTime lastInputTS;
Add comment 6 Plus private T? currentFilter;
Add comment 7 Plus private Task? taskSetInput;
Add comment 8 Plus private int delayInMS;
Add comment 9 Plus public event Func<T, Task>? OnChanged;
Add comment 10 Plus
Add comment 11 Plus public DelayedCallHelper(int delayInMS = 350)
Add comment 12 Plus {
Add comment 13 Plus this.delayInMS = delayInMS;
Add comment 14 Plus }
Add comment 15 Plus
Add comment 16 Plus private async Task ApplyInputAsync()
Add comment 17 Plus {
Add comment 18 Plus while ((DateTime.UtcNow - lastInputTS).TotalMilliseconds < delayInMS)
Add comment 19 Plus await Task.Delay(30);
Add comment 20 Plus
Add comment 21 Plus taskSetInput = null;
Add comment 22 Plus if (OnChanged != null)
Add comment 23 Plus await OnChanged.Invoke(currentFilter);
Add comment 24 Plus }
Add comment 25 Plus
Add comment 26 Plus public void PushInput(T val)
Add comment 27 Plus {
Add comment 28 Plus currentFilter = val;
Add comment 29 Plus lastInputTS = DateTime.UtcNow;
Add comment 30 Plus
Add comment 31 Plus if (taskSetInput == null)
Add comment 32 Plus taskSetInput = ApplyInputAsync();
Add comment 33 Plus }
Add comment 34 Plus }
Add comment 35 Plus }
Add comment 36 Plus
InputHelper.cs
/WPE.App.Shared.BaseComponents/Data/InputHelper.cs+10/WPE.App.Shared.BaseComponents/Data/InputHelper.cs
Add comment 1 Plus namespace WPE.App.Shared.BaseComponents.Data
Add comment 2 Plus {
Add comment 3 Plus public class InputHelper : DelayedCallHelper<string>
Add comment 4 Plus {
Add comment 5 Plus public InputHelper(int delayInMS = 350) : base(delayInMS)
Add comment 6 Plus {
Add comment 7 Plus }
Add comment 8 Plus }
Add comment 9 Plus }
Add comment 10 Plus
SearchbarPeople.razor
/WPE.App.Shared.BaseComponents/Pages/ActionElement/Searchbar/SearchbarPeople.razor+18/WPE.App.Shared.BaseComponents/Pages/ActionElement/Searchbar/SearchbarPeople.razor
Add comment 1 @using Infsoft.WPE.App.Shared.BaseComponents.Pages.Buttons
Add comment 2 Plus @using global::WPE.App.Shared.BaseComponents.Data;
Add comment 2 3
Add comment 3 4 @{
Add comment 4 5 string barClass = "searchbar";
Add comment 25 26 [Parameter]
Add comment 26 27 public EventCallback<string> ValueChanged { get; set; }
Add comment 27 28
Add comment 29 Plus [Parameter]
Add comment 30 Plus public int CallbackDelay { get; set; } = 0;
Add comment 31 Plus
Add comment 28 32 private bool Empty => String.IsNullOrEmpty(Value);
Add comment 29 33
Add comment 34 Plus private InputHelper? inputHelper;
Add comment 35 Plus
Add comment 36 Plus protected override void OnInitialized()
Add comment 37 Plus {
Add comment 38 Plus inputHelper = new InputHelper(CallbackDelay);
Add comment 39 Plus inputHelper.OnChanged += InputHelper_OnChanged;
Add comment 40 Plus }
Add comment 41 Plus
Add comment 30 42 private void OnInput(ChangeEventArgs args)
Add comment 31 43 {
Add comment 32 44 if (args == null) return;
Add comment 42 54 private void SetValue(string value = "")
Add comment 43 55 {
Add comment 44 56 Value = value;
Add comment 57 Plus inputHelper?.PushInput(Value);
Add comment 58 Plus }
Add comment 59 Plus
Add comment 60 Plus async Task InputHelper_OnChanged(string val)
Add comment 61 Plus {
Add comment 45 62 _ = ValueChanged.InvokeAsync(Value);
Add comment 63 Plus await Task.CompletedTask;
Add comment 46 64 }
Add comment 47 65 }
Add comment 48 66
WPE.App.Shared.BaseComponents.csproj
/WPE.App.Shared.BaseComponents/WPE.App.Shared.BaseComponents.csproj-1+1/WPE.App.Shared.BaseComponents/WPE.App.Shared.BaseComponents.csproj
Add comment 15 <PackageIcon>icon.png</PackageIcon>
Add comment 16 <PackageReadmeFile>ReadMe.md</PackageReadmeFile>
Add comment 17 <PackageTags>WPE;Workplace Experience;Blazor;MAUI;infsoft</PackageTags>
Add comment 18 Minus <Version>0.0.16</Version>
Add comment 18 Plus <Version>0.0.17</Version>
Add comment 19 <WarningsAsErrors>RZ10012</WarningsAsErrors>
Add comment 20 </PropertyGroup>
Add comment 21