wabbajack/Wabbajack.App.Blazor/Components/ProgressBar.razor
2022-01-28 12:58:28 +01:00

39 lines
999 B
Plaintext

@using Wabbajack.RateLimiter
@using System
@using System.Reactive.Linq
@implements IDisposable
@namespace Wabbajack.App.Blazor.Components
<div id="progress-bar">
<progress max="1" value="@CurrentProgress.ToString("F")"></progress>
<span class="text">@Text</span>
</div>
@code {
[Parameter] public IObservable<Percent>? ProgressObserver { get; set; }
private double CurrentProgress { get; set; }
private string Text { get; set; } = string.Empty;
private IDisposable? _disposable;
protected override void OnInitialized()
{
if (ProgressObserver is null) return;
_disposable = ProgressObserver
.Sample(TimeSpan.FromMilliseconds(250))
.DistinctUntilChanged(p => p.Value)
.Subscribe(p =>
{
CurrentProgress = p.Value;
Text = p.ToString();
InvokeAsync(StateHasChanged);
});
}
public void Dispose() => _disposable?.Dispose();
}