LibraryManagement / BlazorWebAssembly /Services /NotificationStateService.cs
Yuyuqt
add: real time update notification badge count
313d29f
Raw
History Blame Contribute Delete
590 Bytes
using System;
namespace BlazorWebAssembly.Services
{
public class NotificationStateService
{
public int UnreadCount { get; private set; }
public event Action? OnChange;
public void SetUnreadCount(int count)
{
UnreadCount = count;
NotifyStateChanged();
}
public void DecrementCount()
{
if (UnreadCount > 0)
{
UnreadCount--;
NotifyStateChanged();
}
}
private void NotifyStateChanged() => OnChange?.Invoke();
}
}