Migliorata gestione e visualizzazione notifiche

This commit is contained in:
2025-09-12 15:42:56 +02:00
parent b798b01da0
commit 223e74c490
20 changed files with 229 additions and 60 deletions

View File

@@ -6,12 +6,14 @@
@using salesbook.Shared.Core.Messages.Activity.Copy
@using salesbook.Shared.Core.Messages.Activity.New
@using salesbook.Shared.Core.Messages.Contact
@using salesbook.Shared.Core.Messages.Notification
@using salesbook.Shared.Core.Messages.Notification.Loaded
@using salesbook.Shared.Core.Messages.Notification.NewPush
@inject IDialogService Dialog
@inject IMessenger Messenger
@inject CopyActivityService CopyActivityService
@inject NewPushNotificationService NewPushNotificationService
@inject NotificationState Notification
@inject NotificationsLoadedService NotificationsLoadedService
<div class="container animated-navbar @(IsVisible ? "show-nav" : "hide-nav") @(IsVisible ? PlusVisible ? "with-plus" : "without-plus" : "with-plus")">
<nav class="navbar @(IsVisible ? PlusVisible ? "with-plus" : "without-plus" : "with-plus")">
@@ -68,8 +70,7 @@
protected override Task OnInitializedAsync()
{
CopyActivityService.OnCopyActivity += async dto => await CreateActivity(dto);
NewPushNotificationService.OnNotificationReceived += NewNotificationReceived;
InitMessage();
NavigationManager.LocationChanged += (_, args) =>
{
@@ -117,4 +118,11 @@
Notification.ReceivedNotifications.Add(notification);
InvokeAsync(StateHasChanged);
}
private void InitMessage()
{
CopyActivityService.OnCopyActivity += async dto => await CreateActivity(dto);
NewPushNotificationService.OnNotificationReceived += NewNotificationReceived;
NotificationsLoadedService.OnNotificationsLoaded += () => InvokeAsync(StateHasChanged);
}
}

View File

@@ -0,0 +1,12 @@
<MudOverlay Visible="Visible" DarkBackground="false">
<div class="overlay-container">
<span>Caricamento</span>
<MudProgressLinear Color="Color.Primary" Rounded="true" Size="Size.Medium" Indeterminate="true" />
</div>
</MudOverlay>
@code
{
[Parameter] public bool Visible { get; set; }
}

View File

@@ -0,0 +1,18 @@
.overlay-container {
background: var(--mud-palette-background);
width: 20rem;
height: 6rem;
padding: 0 1rem;
display: flex;
gap: .5rem;
flex-direction: column;
justify-content: center;
border-radius: 20px;
box-shadow: var(--custom-box-shadow);
}
.overlay-container > span {
text-align: center;
font-size: 20px;
font-weight: 600;
}

View File

@@ -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();

View File

@@ -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();

View File

@@ -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;
}

View File

@@ -1,6 +1,5 @@
@using salesbook.Shared.Components.Layout.Spinner
@using salesbook.Shared.Core.Dto
@using salesbook.Shared.Core.Interface
@using salesbook.Shared.Components.Layout.Overlay
@using salesbook.Shared.Core.Interface.IntegryApi
@inject IIntegryApiService IntegryApiService

View File

@@ -1,6 +1,12 @@
@using salesbook.Shared.Components.Layout.Spinner
@using salesbook.Shared.Core.Dto.Activity
@using salesbook.Shared.Core.Entity
@using salesbook.Shared.Core.Interface
@inject IManageDataService ManageDataService
@inject ISnackbar Snackbar
@inject IDialogService Dialog
<div class="row" id="@Notification.Id">
<div class="row" id="@Notification.Id" @onclick="OpenActivity">
<div class="behind-left">
<button class="read-btn">
<MudIcon Icon="@Icons.Material.Rounded.Check" />
@@ -51,10 +57,35 @@
</div>
</div>
<OverlayLayout Visible="VisibleOverlay" />
@code {
[Parameter] public bool Unread { get; set; }
[Parameter] public WtbNotification Notification { get; set; } = new();
private bool VisibleOverlay { get; set; }
private async Task OpenActivity()
{
if(Notification.NotificationData?.ActivityId == null) return;
var activityId = Notification.NotificationData.ActivityId;
Snackbar.Configuration.PositionClass = Defaults.Classes.Position.TopCenter;
Snackbar.Clear();
VisibleOverlay = true;
StateHasChanged();
var activity = (await ManageDataService.GetActivityTryLocalDb(new WhereCondActivity { ActivityId = activityId })).LastOrDefault();
VisibleOverlay = false;
StateHasChanged();
if (activity == null) Snackbar.Add("Impossibile aprire l'attivit<69>", Severity.Error);
_ = ModalHelpers.OpenActivityForm(Dialog, activity, null);
}
private static string GetTimeAgo(DateTime? timestamp)
{
if (timestamp is null) return "";
@@ -77,7 +108,7 @@
return $"{timestamp.Value:t}";
default:
{
return difference.TotalDays < 7 ? $"{(int)difference.TotalDays}g fa" : timestamp.Value.ToString("dd/MM/yyyy");
return timestamp.Value.ToString("dd/MM/yyyy");
}
}
}