Files

63 lines
1.1 KiB
Plaintext

@using System.Timers
@using WebAssembly.Components.Feedback
@using WebAssembly.Data
@implements IDisposable;
@inject IToastService ToastService
@if (ToastService.HasToasts())
{
<div class="toastsContainer">
@foreach (var toast in Toasts)
{
<ToastComponent Toast="toast"/>
}
</div>
}
<style>
.toastsContainer {
position: fixed;
top: 64px;
right: 64px;
display: flex;
flex-direction: column;
gap: 5px;
}
</style>
@code {
private List<ToastModel> Toasts => ToastService.GetToasts();
private Timer _ageTimer = null!;
protected override void OnInitialized()
{
base.OnInitialized();
ToastService.Subscribe(OnUpdate);
_ageTimer = new Timer(10);
_ageTimer.Elapsed += OnAge!;
_ageTimer.Enabled = true;
}
void IDisposable.Dispose()
{
ToastService.Unsubscribe(OnUpdate);
}
void OnAge(object? sender, ElapsedEventArgs elapsedEventArgs)
{
ToastService.AgeToasts();
_ageTimer.Enabled = true;
}
void OnUpdate()
{
StateHasChanged();
}
}