wabbajack/Wabbajack.App.Blazor/Components/ProgressBar.razor

39 lines
999 B
Plaintext
Raw Normal View History

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