Migliorata gestione e visualizzazione notifiche
This commit is contained in:
@@ -1,15 +1,19 @@
|
||||
@page "/"
|
||||
@attribute [Authorize]
|
||||
@using CommunityToolkit.Mvvm.Messaging
|
||||
@using salesbook.Shared.Core.Interface
|
||||
@using salesbook.Shared.Components.Layout.Spinner
|
||||
@using salesbook.Shared.Core.Interface.System.Network
|
||||
@using salesbook.Shared.Core.Interface.System.Notification
|
||||
@using salesbook.Shared.Core.Messages.Notification.Loaded
|
||||
@using salesbook.Shared.Core.Services
|
||||
@inject IFormFactor FormFactor
|
||||
@inject INetworkService NetworkService
|
||||
@inject IFirebaseNotificationService FirebaseNotificationService
|
||||
@inject IShinyNotificationManager NotificationManager
|
||||
@inject INotificationService NotificationService
|
||||
@inject PreloadService PreloadService
|
||||
@inject IMessenger Messenger
|
||||
|
||||
<SpinnerLayout FullScreen="true" />
|
||||
|
||||
@@ -17,6 +21,7 @@
|
||||
{
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
await LoadNotification();
|
||||
await CheckAndRequestPermissions();
|
||||
|
||||
try
|
||||
@@ -40,6 +45,12 @@
|
||||
NavigationManager.NavigateTo("/Calendar");
|
||||
}
|
||||
|
||||
private async Task LoadNotification()
|
||||
{
|
||||
await NotificationService.LoadNotification();
|
||||
Messenger.Send(new NotificationsLoadedMessage());
|
||||
}
|
||||
|
||||
private async Task CheckAndRequestPermissions()
|
||||
{
|
||||
await NotificationManager.RequestAccess();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -1,6 +1,21 @@
|
||||
.container-notifications {
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
padding: .2rem 0 75px 0;
|
||||
}
|
||||
|
||||
.list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.container-notifications::-webkit-scrollbar {
|
||||
width: 6px;
|
||||
}
|
||||
|
||||
.container-notifications::-webkit-scrollbar-thumb {
|
||||
background: #bbb;
|
||||
border-radius: 3px;
|
||||
}
|
||||
Reference in New Issue
Block a user