wabbajack/Wabbajack.App.Blazor/Components/ProgressBar.razor
2022-01-28 16:05:30 +11:00

33 lines
856 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 void OnInitialized()
{
var textPercentage = string.IsNullOrEmpty(Text);
ProgressObserver
.Sample(TimeSpan.FromMilliseconds(250))
.DistinctUntilChanged(p => p.Value)
.Subscribe(p => {
CurrentProgress = p.Value;
if (textPercentage) Text = p.ToString();
InvokeAsync(StateHasChanged);
});
}
}