Wave/Wave/Components/ToastComponent.razor

36 lines
880 B
Plaintext
Raw Normal View History

@using Wave.Utilities
@implements IDisposable
@inject IMessageDisplay Messages
@rendermode InteractiveServer
<div class="toast toast-start z-10 whitespace-normal" role="alert">
@foreach (var message in MessagesDisplayed) {
<div class="alert @message.Type max-w-sm" @onclick="() => MessagesDisplayed.Remove(message)">
2024-01-16 16:35:30 +00:00
@if (message.Title is null) {
@message.Body
} else {
<span class="font-bold">@message.Title</span>
<span><small>@message.Body</small></span>
}
</div>
}
</div>
@code {
private List<IMessageDisplay.Message> MessagesDisplayed { get; } = [];
2024-01-16 16:35:30 +00:00
protected override void OnInitialized() {
Messages.OnMessage += OnMessage;
}
private bool OnMessage(IMessageDisplay.Message message) {
MessagesDisplayed.Add(message);
InvokeAsync(StateHasChanged);
return true;
}
public void Dispose() {
Messages.OnMessage -= OnMessage;
2024-01-16 16:35:30 +00:00
}
}