UI performance improvements.
This commit is contained in:
17
JSMR.UI.Blazor/Components/SkeletonGrid.razor
Normal file
17
JSMR.UI.Blazor/Components/SkeletonGrid.razor
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<div class="products-grid">
|
||||||
|
@for (int i = 0; i < Count; i++)
|
||||||
|
{
|
||||||
|
<div class="card">
|
||||||
|
<BitShimmer IsDataLoaded="false" Height="160px" Width="100%" />
|
||||||
|
<div class="card-body">
|
||||||
|
<BitShimmer IsDataLoaded="false" Height="16px" Width="70%" class="mt-2" />
|
||||||
|
<BitShimmer IsDataLoaded="false" Height="12px" Width="40%" class="mt-1" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@code {
|
||||||
|
[Parameter]
|
||||||
|
public int Count { get; set; } = 12;
|
||||||
|
}
|
||||||
@@ -15,7 +15,6 @@
|
|||||||
<h3>Voice Works</h3>
|
<h3>Voice Works</h3>
|
||||||
|
|
||||||
<VoiceWorkFilters Value="@FilterState" ValueChanged="OnFilterStateChanged" />
|
<VoiceWorkFilters Value="@FilterState" ValueChanged="OnFilterStateChanged" />
|
||||||
|
|
||||||
<JProductCollection Products="searchResults?.Items"></JProductCollection>
|
<JProductCollection Products="searchResults?.Items"></JProductCollection>
|
||||||
|
|
||||||
@if (searchResults is not null)
|
@if (searchResults is not null)
|
||||||
@@ -28,7 +27,9 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
|
private bool _suppressNextLocation;
|
||||||
private bool _isAlive = true;
|
private bool _isAlive = true;
|
||||||
|
//private bool IsLoading;
|
||||||
private CancellationTokenSource _cts = new();
|
private CancellationTokenSource _cts = new();
|
||||||
|
|
||||||
VoiceWorkFilterState FilterState = new();
|
VoiceWorkFilterState FilterState = new();
|
||||||
@@ -44,21 +45,26 @@
|
|||||||
|
|
||||||
private async void OnLocationChanged(object? sender, LocationChangedEventArgs e)
|
private async void OnLocationChanged(object? sender, LocationChangedEventArgs e)
|
||||||
{
|
{
|
||||||
|
if (_suppressNextLocation)
|
||||||
|
{
|
||||||
|
_suppressNextLocation = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!_isAlive)
|
if (!_isAlive)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!IsThisPage(e.Location))
|
if (!IsThisPage(e.Location))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Parse query from the new URL and update state if it actually changed.
|
|
||||||
string query = NavigationManager.ToAbsoluteUri(e.Location).Query;
|
string query = NavigationManager.ToAbsoluteUri(e.Location).Query;
|
||||||
VoiceWorkFilterState next = VoiceWorkFilterState.FromQuery(query);
|
VoiceWorkFilterState next = VoiceWorkFilterState.FromQuery(query);
|
||||||
|
|
||||||
if (next != FilterState)
|
if (next != FilterState)
|
||||||
{
|
{
|
||||||
FilterState = next;
|
FilterState = next;
|
||||||
await RunSearchAsync();
|
|
||||||
await InvokeAsync(StateHasChanged);
|
await InvokeAsync(StateHasChanged);
|
||||||
|
RunSearchAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,7 +80,13 @@
|
|||||||
if (next == FilterState)
|
if (next == FilterState)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
FilterState = next;
|
||||||
|
|
||||||
|
// Optional immediate paint if you want instant visual feedback on filters:
|
||||||
|
//await InvokeAsync(StateHasChanged);
|
||||||
|
|
||||||
UpdateUrl(next, false);
|
UpdateUrl(next, false);
|
||||||
|
RunSearchAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateUrl(VoiceWorkFilterState next, bool replace)
|
void UpdateUrl(VoiceWorkFilterState next, bool replace)
|
||||||
@@ -82,6 +94,8 @@
|
|||||||
string basePath = new Uri(NavigationManager.Uri).GetLeftPart(UriPartial.Path);
|
string basePath = new Uri(NavigationManager.Uri).GetLeftPart(UriPartial.Path);
|
||||||
string uri = QueryHelpers.AddQueryString(basePath, next.ToQuery());
|
string uri = QueryHelpers.AddQueryString(basePath, next.ToQuery());
|
||||||
|
|
||||||
|
_suppressNextLocation = true;
|
||||||
|
|
||||||
NavigationManager.NavigateTo(uri, replace: replace);
|
NavigationManager.NavigateTo(uri, replace: replace);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,6 +105,9 @@
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
//IsLoading = true; // show skeletons NOW
|
||||||
|
//StateHasChanged(); // paint immediately
|
||||||
|
|
||||||
_cts.Cancel();
|
_cts.Cancel();
|
||||||
_cts = new();
|
_cts = new();
|
||||||
|
|
||||||
@@ -99,7 +116,15 @@
|
|||||||
}
|
}
|
||||||
catch (OperationCanceledException)
|
catch (OperationCanceledException)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (_isAlive)
|
||||||
|
{
|
||||||
|
//IsLoading = false; // hide skeletons
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user