30 lines
971 B
Plaintext
30 lines
971 B
Plaintext
@* NotificationBadge.razor — cloche avec badge compteur temps réel (SignalR). *@
|
|||
|
|
@implements IAsyncDisposable
|
||
|
|
@inject NotificationsHubClient Hub
|
||
|
|
@inject NavigationManager Navigation
|
||
|
|
|
||
|
|
<MudTooltip Text="Notifications">
|
||
|
|
<MudIconButton Icon="@Icons.Material.Filled.Notifications" Color="Color.Inherit" aria-label="Notifications"
|
||
|
|
OnClick="@(() => Navigation.NavigateTo("/events"))">
|
||
|
|
@if (Hub.UnreadCount > 0)
|
||
|
|
{
|
||
|
|
<MudBadge Color="Color.Error" Overlap="true" Bordered="true" Content="@Hub.UnreadCount" />
|
||
|
|
}
|
||
|
|
</MudIconButton>
|
||
|
|
</MudTooltip>
|
||
|
|
|
||
|
|
@code {
|
||
|
|
protected override async Task OnInitializedAsync()
|
||
|
|
{
|
||
|
|
Hub.UnreadCountChanged += OnUnreadChanged;
|
||
|
|
await Hub.StartAsync();
|
||
|
|
}
|
||
|
|
|
||
|
|
private void OnUnreadChanged(int _) => InvokeAsync(StateHasChanged);
|
||
|
|
|
||
|
|
public async ValueTask DisposeAsync()
|
||
|
|
{
|
||
|
|
Hub.UnreadCountChanged -= OnUnreadChanged;
|
||
|
|
await Hub.DisposeAsync();
|
||
|
|
}
|
||
|
|
}
|