2026-08-10 22:49:37 +02:00
|
|
|
@* NotificationBadge.razor — cloche avec badge compteur temps réel (SignalR). *@
|
|
|
|
|
@implements IAsyncDisposable
|
|
|
|
|
@inject NotificationsHubClient Hub
|
|
|
|
|
@inject NavigationManager Navigation
|
2026-10-25 18:01:15 +01:00
|
|
|
@inject AuthenticationStateProvider AuthenticationStateProvider
|
2026-10-25 05:59:18 +01:00
|
|
|
@inject Heimdall.Web.Services.UiText Text
|
2026-08-10 22:49:37 +02:00
|
|
|
|
2026-10-25 05:59:18 +01:00
|
|
|
<MudTooltip Text="@Text["SharedNotificationBadge_Title"]">
|
2026-10-25 18:33:40 +01:00
|
|
|
<MudBadge Color="Color.Error" Overlap="true" Bordered="true" Content="@Hub.UnreadCount"
|
|
|
|
|
Visible="@(Hub.UnreadCount > 0)">
|
|
|
|
|
<MudIconButton Icon="@Icons.Material.Filled.Notifications" Color="Color.Inherit"
|
|
|
|
|
aria-label="@Text["SharedNotificationBadge_Title"]"
|
|
|
|
|
OnClick="@(() => Navigation.NavigateTo("/events"))" />
|
|
|
|
|
</MudBadge>
|
2026-08-10 22:49:37 +02:00
|
|
|
</MudTooltip>
|
|
|
|
|
|
|
|
|
|
@code {
|
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
|
|
|
{
|
|
|
|
|
Hub.UnreadCountChanged += OnUnreadChanged;
|
2026-10-25 18:01:15 +01:00
|
|
|
AuthenticationStateProvider.AuthenticationStateChanged += OnAuthenticationStateChanged;
|
2026-08-10 22:49:37 +02:00
|
|
|
await Hub.StartAsync();
|
2026-10-25 18:15:45 +01:00
|
|
|
await Hub.RefreshUnreadCountAsync();
|
2026-08-10 22:49:37 +02:00
|
|
|
}
|
|
|
|
|
|
2026-10-25 18:01:15 +01:00
|
|
|
private void OnAuthenticationStateChanged(Task<AuthenticationState> authenticationStateTask)
|
|
|
|
|
{
|
|
|
|
|
_ = InvokeAsync(async () =>
|
|
|
|
|
{
|
|
|
|
|
var authenticationState = await authenticationStateTask;
|
|
|
|
|
if (authenticationState.User.Identity?.IsAuthenticated == true)
|
2026-10-25 18:15:45 +01:00
|
|
|
{
|
2026-10-25 18:01:15 +01:00
|
|
|
await Hub.StartAsync();
|
2026-10-25 18:15:45 +01:00
|
|
|
await Hub.RefreshUnreadCountAsync();
|
|
|
|
|
}
|
2026-10-25 18:01:15 +01:00
|
|
|
StateHasChanged();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-10 22:49:37 +02:00
|
|
|
private void OnUnreadChanged(int _) => InvokeAsync(StateHasChanged);
|
|
|
|
|
|
|
|
|
|
public async ValueTask DisposeAsync()
|
|
|
|
|
{
|
|
|
|
|
Hub.UnreadCountChanged -= OnUnreadChanged;
|
2026-10-25 18:01:15 +01:00
|
|
|
AuthenticationStateProvider.AuthenticationStateChanged -= OnAuthenticationStateChanged;
|
2026-08-10 22:49:37 +02:00
|
|
|
await Hub.DisposeAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|