initial commit
This commit is contained in:
41
Lab505.Client/Pages/NotificationProvider.razor
Normal file
41
Lab505.Client/Pages/NotificationProvider.razor
Normal file
@@ -0,0 +1,41 @@
|
||||
@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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user