42 lines
1.1 KiB
Plaintext
42 lines
1.1 KiB
Plaintext
@implements IAsyncDisposable
|
|
@inject StateService State
|
|
@inject ISnackbar Snackbar
|
|
@inject ScriptLogService ScriptLog
|
|
|
|
@* Component không render gì — lắng nghe notification, ghi vào output log + Snackbar *@
|
|
|
|
@code {
|
|
[Parameter] public bool Muted { get; set; }
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
await State.StartAsync();
|
|
State.NotificationReceived += OnNotification;
|
|
}
|
|
|
|
private void OnNotification(NotificationDto n)
|
|
{
|
|
ScriptLog.LogNotification(n);
|
|
|
|
// Snackbar toast — chỉ khi chưa tắt
|
|
if (!Muted)
|
|
{
|
|
var severity = n.Level switch
|
|
{
|
|
"success" => Severity.Success,
|
|
"error" => Severity.Error,
|
|
"warning" => Severity.Warning,
|
|
"heartbeat" => Severity.Normal,
|
|
_ => Severity.Info,
|
|
};
|
|
Snackbar.Add(n.Message, severity);
|
|
}
|
|
}
|
|
|
|
public ValueTask DisposeAsync()
|
|
{
|
|
State.NotificationReceived -= OnNotification;
|
|
return ValueTask.CompletedTask;
|
|
}
|
|
}
|