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