Migliorata gestione e visualizzazione notifiche
This commit is contained in:
@@ -1,20 +1,25 @@
|
||||
@page "/Notifications"
|
||||
@attribute [Authorize]
|
||||
@using CommunityToolkit.Mvvm.Messaging
|
||||
@using salesbook.Shared.Components.Layout
|
||||
@using salesbook.Shared.Components.Layout.Spinner
|
||||
@using salesbook.Shared.Components.SingleElements
|
||||
@using salesbook.Shared.Core.Dto.PageState
|
||||
@using salesbook.Shared.Core.Entity
|
||||
@using salesbook.Shared.Core.Interface
|
||||
@using salesbook.Shared.Core.Interface.IntegryApi
|
||||
@using salesbook.Shared.Core.Messages.Notification
|
||||
@using salesbook.Shared.Core.Messages.Notification.Loaded
|
||||
@using salesbook.Shared.Core.Messages.Notification.NewPush
|
||||
@inject NotificationState Notification
|
||||
@inject NewPushNotificationService NewPushNotificationService
|
||||
@inject IJSRuntime JS
|
||||
@inject IIntegryNotificationRestClient IntegryNotificationRestClient
|
||||
@inject INotificationService NotificationService
|
||||
@inject IMessenger Messenger
|
||||
|
||||
<HeaderLayout Title="Notifiche" />
|
||||
|
||||
<div class="container">
|
||||
<div class="container container-notifications">
|
||||
@if (Loading)
|
||||
{
|
||||
<SpinnerLayout FullScreen="true" />
|
||||
@@ -50,7 +55,7 @@
|
||||
|
||||
@code {
|
||||
private DotNetObjectReference<Notifications>? _objectReference;
|
||||
private bool Loading { get; set; } = true;
|
||||
private bool Loading { get; set; }
|
||||
|
||||
protected override Task OnInitializedAsync()
|
||||
{
|
||||
@@ -62,37 +67,6 @@
|
||||
protected override async Task OnAfterRenderAsync(bool firstRender)
|
||||
{
|
||||
await JS.InvokeVoidAsync("initNotifications", _objectReference);
|
||||
|
||||
if (firstRender)
|
||||
{
|
||||
await LoadData();
|
||||
Loading = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task LoadData()
|
||||
{
|
||||
var allNotifications = await IntegryNotificationRestClient.Get();
|
||||
var allIds = allNotifications.Select(n => n.Id).ToHashSet();
|
||||
|
||||
Notification.ReceivedNotifications = Notification.ReceivedNotifications
|
||||
.Where(r => !allIds.Contains(r.Id))
|
||||
.ToList();
|
||||
|
||||
Notification.UnreadNotifications = allNotifications
|
||||
.Where(x =>
|
||||
x.WtbDeviceNotifications == null ||
|
||||
x.WtbDeviceNotifications.Any(y => y.ReadDate == null))
|
||||
.ToList();
|
||||
|
||||
Notification.NotificationsRead = allNotifications
|
||||
.Where(x =>
|
||||
x.WtbDeviceNotifications != null &&
|
||||
x.WtbDeviceNotifications.All(y => y.ReadDate != null))
|
||||
.ToList();
|
||||
|
||||
OrderNotificationList();
|
||||
}
|
||||
|
||||
private void NewNotificationReceived(WtbNotification notification)
|
||||
@@ -119,7 +93,7 @@
|
||||
|
||||
if (!removed) return;
|
||||
|
||||
OrderNotificationList();
|
||||
NotificationService.OrderNotificationList();
|
||||
Loading = false;
|
||||
_ = InvokeAsync(StateHasChanged);
|
||||
|
||||
@@ -127,6 +101,8 @@
|
||||
{
|
||||
_ = IntegryNotificationRestClient.Delete(notificationId);
|
||||
});
|
||||
|
||||
Messenger.Send(new NotificationsLoadedMessage());
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
@@ -155,23 +131,12 @@
|
||||
wtbNotification = await IntegryNotificationRestClient.MarkAsRead(notificationId);
|
||||
Notification.NotificationsRead.Add(wtbNotification);
|
||||
|
||||
OrderNotificationList();
|
||||
NotificationService.OrderNotificationList();
|
||||
Messenger.Send(new NotificationsLoadedMessage());
|
||||
Loading = false;
|
||||
StateHasChanged();
|
||||
}
|
||||
|
||||
private void OrderNotificationList()
|
||||
{
|
||||
Notification.ReceivedNotifications = Notification.ReceivedNotifications
|
||||
.OrderByDescending(x => x.StartDate).ToList();
|
||||
|
||||
Notification.UnreadNotifications = Notification.UnreadNotifications
|
||||
.OrderByDescending(x => x.StartDate).ToList();
|
||||
|
||||
Notification.NotificationsRead = Notification.NotificationsRead
|
||||
.OrderByDescending(x => x.StartDate).ToList();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_objectReference?.Dispose();
|
||||
|
||||
Reference in New Issue
Block a user