wabbajack/Wabbajack.App.Blazor/Components/ProgressBar.razor
Unnoen d1e64e910c
ProgressBar IObservable. Basic Modal. No longer download list if exists.
.Sample() is what .Throttle() sounds like it does.
ProgressBar will be changed again, this implementation feels dirty.
2022-01-27 18:48:32 +11:00

35 lines
895 B
Plaintext

@using Wabbajack.RateLimiter
@using System
@using System.Reactive.Linq
@namespace Wabbajack.App.Blazor.Components
<div id="progress-bar">
<progress value="@CurrentProgress"></progress>
<span class="text">@Text</span>
</div>
@code {
private double CurrentProgress { get; set; }
[Parameter] public IObservable<Percent> ProgressObserver { get; set; }
[Parameter] public string Text { get; set; }
protected override Task OnInitializedAsync()
{
var textPercentage = string.IsNullOrEmpty(Text);
ProgressObserver
.Sample(TimeSpan.FromMilliseconds(250))
.DistinctUntilChanged()
.Subscribe(p => {
CurrentProgress = p.Value;
if (textPercentage) Text = p.ToString();
InvokeAsync(StateHasChanged);
});
return base.OnInitializedAsync();
}
}