| | 1 | | @using Syki.Front.Features.Cross.ViewNotifications |
| | 2 | |
|
| | 3 | | @namespace Syki.Front.Features.Cross.GetUserNotifications |
| | 4 | |
|
| | 5 | | <div> |
| 0 | 6 | | @if (_alert) |
| | 7 | | { |
| | 8 | | <MudBadge Content="@(GetCount())" Color="Color.Error" Overlap="true" BadgeClass="syki-badge-icon"> |
| | 9 | | <MudIconButton OnClick="@ViewAndOpenDialog" Icon="@Icons.Material.Filled.NotificationsActive" Style="color: |
| | 10 | | </MudBadge> |
| | 11 | | } |
| | 12 | | else |
| | 13 | | { |
| | 14 | | <MudIconButton Icon="@Icons.Material.Filled.NotificationsNone" OnClick="@OpenDialog" Color="Color.Inherit" /> |
| | 15 | | } |
| | 16 | | </div> |
| | 17 | |
|
| | 18 | | @inject IDialogService DialogService |
| | 19 | | @inject IBrowserViewportService BrowserViewportService |
| | 20 | | @inject ViewNotificationsClient ViewNotificationsClient |
| | 21 | | @inject GetUserNotificationsClient GetUserNotificationsClient |
| | 22 | |
|
| | 23 | | @code |
| | 24 | | { |
| | 25 | | private bool _alert = false; |
| 0 | 26 | | private List<UserNotificationOut> _notifications = []; |
| | 27 | |
|
| | 28 | | protected override async Task OnInitializedAsync() |
| | 29 | | { |
| 0 | 30 | | await GetNotifications(); |
| 0 | 31 | | _alert = _notifications.Any(x => x.ViewedAt == null); |
| 0 | 32 | | } |
| | 33 | |
|
| | 34 | | private string GetCount() |
| | 35 | | { |
| 0 | 36 | | return _notifications.Count < 10 ? _notifications.Count.ToString() : "9+"; |
| | 37 | | } |
| | 38 | |
|
| | 39 | | private async Task GetNotifications() |
| | 40 | | { |
| 0 | 41 | | _notifications = await GetUserNotificationsClient.Get(); |
| 0 | 42 | | } |
| | 43 | |
|
| | 44 | | private async Task ViewAndOpenDialog() |
| | 45 | | { |
| 0 | 46 | | _alert = false; |
| 0 | 47 | | await OpenDialog(); |
| 0 | 48 | | await ViewNotificationsClient.View(); |
| 0 | 49 | | await GetNotifications(); |
| 0 | 50 | | StateHasChanged(); |
| 0 | 51 | | } |
| | 52 | |
|
| | 53 | | private async Task OpenDialog() |
| | 54 | | { |
| 0 | 55 | | var breakpoint = await BrowserViewportService.GetCurrentBreakpointAsync(); |
| 0 | 56 | | var options = new DialogOptions { |
| 0 | 57 | | MaxWidth = MaxWidth.Medium, |
| 0 | 58 | | FullWidth = true, |
| 0 | 59 | | FullScreen = breakpoint == Breakpoint.Xs, |
| 0 | 60 | | }; |
| 0 | 61 | | var dialog = await DialogService.ShowAsync<ViewNotificationsDialog>("", options); |
| | 62 | |
|
| 0 | 63 | | var result = await dialog.Result; |
| | 64 | |
|
| 0 | 65 | | if (result!.Canceled) return; |
| | 66 | |
|
| 0 | 67 | | await GetNotifications(); |
| 0 | 68 | | } |
| | 69 | | } |