@implements IDisposable;
@inject IToastService toastService
@if (toastService.HasToasts())
{
@foreach(var toast in Toasts)
{
}
}
@code {
private List Toasts => toastService.GetToasts();
private Timer ageTimer = null!;
protected override void OnInitialized()
{
toastService.Subscribe(OnUpdate);
ageTimer = new Timer(10);
ageTimer.Elapsed += OnAge!;
ageTimer.Enabled = true;
}
public void Dispose()
{
toastService.Unsubscribe(OnUpdate);
}
void OnAge(object? sender, ElapsedEventArgs elapsedEventArgs)
{
toastService.AgeToasts();
ageTimer.Enabled = true;
}
void OnUpdate()
{
StateHasChanged();
}
}