Gestita pagina notifiche

This commit is contained in:
2025-09-11 16:06:19 +02:00
parent 7319378e75
commit 7bfe67a97c
30 changed files with 611 additions and 105 deletions

View File

@@ -24,6 +24,7 @@
padding-bottom: 1rem;
overflow-x: hidden;
overflow-y: visible;
min-height: 7rem;
}
.week-slider.expanded {
@@ -31,7 +32,7 @@
grid-template-columns: repeat(7, 1fr);
gap: 0.4rem;
padding: 1rem;
overflow-y: auto;
overflow-y: hidden;
}
.week-slider.expand-animation { animation: expandFromCenter 0.3s ease forwards; }
@@ -122,8 +123,7 @@
flex-direction: column;
-ms-overflow-style: none;
scrollbar-width: none;
padding-bottom: 16vh;
height: calc(100% - 130px);
padding-bottom: 9vh;
}
.appointments.ah-calendar-m { height: calc(100% - 315px) !important; }

View File

@@ -1,46 +1,179 @@
@page "/Notifications"
@attribute [Authorize]
@using salesbook.Shared.Components.Layout
@using salesbook.Shared.Components.Layout.Spinner
@using salesbook.Shared.Components.SingleElements
@using salesbook.Shared.Core.Dto.Notification
@using salesbook.Shared.Core.Dto.PageState
@using salesbook.Shared.Core.Entity
@using salesbook.Shared.Core.Interface.IntegryApi
@using salesbook.Shared.Core.Messages.Notification
@inject NotificationState Notification
@inject NewPushNotificationService NewPushNotificationService
@inject IJSRuntime JS
@inject IIntegryNotificationRestClient IntegryNotificationRestClient
<HeaderLayout Title="Notifiche" />
<div class="container">
@if (Notification.UnreadNotifications.IsNullOrEmpty())
@if (Loading)
{
<NoDataAvailable Text="Nessuna notifica meno recente" />
<SpinnerLayout FullScreen="true" />
}
else
{
<div class="list" id="list">
@foreach(var notification in Notification.UnreadNotifications)
{
<NotificationCard Notification="notification" />
}
</div>
if (Notification.ReceivedNotifications.IsNullOrEmpty() && Notification.UnreadNotifications.IsNullOrEmpty() && Notification.NotificationsRead.IsNullOrEmpty())
{
<NoDataAvailable Text="Nessuna notifica meno recente" />
}
else
{
<div class="list" id="list">
@foreach(var notification in Notification.ReceivedNotifications)
{
<NotificationCard Unread="true" Notification="notification" />
}
@foreach(var notification in Notification.UnreadNotifications)
{
<NotificationCard Unread="true" Notification="notification" />
}
@foreach (var notification in Notification.NotificationsRead)
{
<NotificationCard Notification="notification" />
}
</div>
}
}
</div>
@code {
private DotNetObjectReference<Notifications>? _objectReference;
private bool Loading { get; set; } = true;
protected override Task OnInitializedAsync()
{
_objectReference = DotNetObjectReference.Create(this);
NewPushNotificationService.OnNotificationReceived += NewNotificationReceived;
return Task.CompletedTask;
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await JS.InvokeVoidAsync("initNotifications");
await JS.InvokeVoidAsync("initNotifications", _objectReference);
if (firstRender)
{
await LoadData();
Loading = false;
StateHasChanged();
}
}
private void NewNotificationReceived(PushNotificationDTO notification)
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)
{
InvokeAsync(StateHasChanged);
}
[JSInvokable]
public async Task Delete(string id)
{
Loading = true;
_ = InvokeAsync(StateHasChanged);
if (!long.TryParse(id, out var notificationId)) return;
var removed = false;
if (Notification.ReceivedNotifications.RemoveAll(x => x.Id == notificationId) > 0)
removed = true;
else if (Notification.UnreadNotifications.RemoveAll(x => x.Id == notificationId) > 0)
removed = true;
else if (Notification.NotificationsRead.RemoveAll(x => x.Id == notificationId) > 0)
removed = true;
if (!removed) return;
OrderNotificationList();
Loading = false;
_ = InvokeAsync(StateHasChanged);
_ = Task.Run(() =>
{
_ = IntegryNotificationRestClient.Delete(notificationId);
});
}
[JSInvokable]
public async Task MarkAsRead(string id)
{
Loading = true;
_ = InvokeAsync(StateHasChanged);
var notificationId = long.Parse(id);
var wtbNotification = Notification.ReceivedNotifications
.FindLast(x => x.Id == notificationId);
if (wtbNotification == null)
{
wtbNotification = Notification.UnreadNotifications
.FindLast(x => x.Id == notificationId);
Notification.UnreadNotifications.Remove(wtbNotification!);
}
else
{
Notification.ReceivedNotifications.Remove(wtbNotification);
}
wtbNotification = await IntegryNotificationRestClient.MarkAsRead(notificationId);
Notification.NotificationsRead.Add(wtbNotification);
OrderNotificationList();
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();
}
}

View File

@@ -143,6 +143,7 @@
max-height: 32vh;
overflow: auto;
scrollbar-width: none;
padding: 1rem 0;
}
.container-pers-rif::-webkit-scrollbar { display: none; }

View File

@@ -5,8 +5,7 @@
flex-direction: column;
-ms-overflow-style: none;
scrollbar-width: none;
padding-bottom: 70px;
height: 100%;
padding-bottom: 9vh;
}
.users .divider {