diff --git a/salesbook.Maui/Core/System/Notification/Push/PushNotificationDelegate.cs b/salesbook.Maui/Core/System/Notification/Push/PushNotificationDelegate.cs index 97b9964..d031d57 100644 --- a/salesbook.Maui/Core/System/Notification/Push/PushNotificationDelegate.cs +++ b/salesbook.Maui/Core/System/Notification/Push/PushNotificationDelegate.cs @@ -1,8 +1,11 @@ using CommunityToolkit.Mvvm.Messaging; +using salesbook.Shared.Core.Dto; using salesbook.Shared.Core.Entity; +using salesbook.Shared.Core.Helpers; using salesbook.Shared.Core.Interface.IntegryApi; using salesbook.Shared.Core.Messages.Notification.NewPush; using Shiny.Push; +using System.Text.Json; namespace salesbook.Maui.Core.System.Notification.Push; @@ -20,10 +23,25 @@ public class PushNotificationDelegate( public Task OnReceived(PushNotification notification) { if (notification.Notification is null) return Task.CompletedTask; + var data = notification.Data; + + NotificationDataDTO? notificationDataDto = null; + + if (!data.IsNullOrEmpty()) + { + var json = JsonSerializer.Serialize(data); + notificationDataDto = JsonSerializer.Deserialize(json); + } + + if (notificationDataDto?.NotificationId == null) return Task.CompletedTask; + var notificationId = long.Parse(notificationDataDto.NotificationId); + var pushNotification = new WtbNotification { + Id = notificationId, Title = notification.Notification.Title, - Body = notification.Notification.Message + Body = notification.Notification.Message, + NotificationData = notificationDataDto }; messenger.Send(new NewPushNotificationMessage(pushNotification)); diff --git a/salesbook.Shared/Components/Pages/Notifications.razor b/salesbook.Shared/Components/Pages/Notifications.razor index fcf242f..603f3e9 100644 --- a/salesbook.Shared/Components/Pages/Notifications.razor +++ b/salesbook.Shared/Components/Pages/Notifications.razor @@ -77,11 +77,11 @@ [JSInvokable] public async Task Delete(string id) { - Loading = true; - _ = InvokeAsync(StateHasChanged); - if (!long.TryParse(id, out var notificationId)) return; + Loading = true; + StateHasChanged(); + var removed = false; if (Notification.ReceivedNotifications.RemoveAll(x => x.Id == notificationId) > 0) @@ -91,16 +91,18 @@ else if (Notification.NotificationsRead.RemoveAll(x => x.Id == notificationId) > 0) removed = true; - if (!removed) return; + if (!removed) + { + Loading = false; + StateHasChanged(); + return; + } + + await IntegryNotificationRestClient.Delete(notificationId); NotificationService.OrderNotificationList(); Loading = false; - _ = InvokeAsync(StateHasChanged); - - _ = Task.Run(() => - { - _ = IntegryNotificationRestClient.Delete(notificationId); - }); + StateHasChanged(); Messenger.Send(new NotificationsLoadedMessage()); } @@ -109,7 +111,7 @@ public async Task MarkAsRead(string id) { Loading = true; - _ = InvokeAsync(StateHasChanged); + StateHasChanged(); var notificationId = long.Parse(id); diff --git a/salesbook.Shared/Components/SingleElements/Card/NotificationCard.razor b/salesbook.Shared/Components/SingleElements/Card/NotificationCard.razor index 03655b3..a6b98a1 100644 --- a/salesbook.Shared/Components/SingleElements/Card/NotificationCard.razor +++ b/salesbook.Shared/Components/SingleElements/Card/NotificationCard.razor @@ -47,11 +47,11 @@ Notification.StartDate < DateTime.Today && Notification.Body != null && Notification.Body.Contains("Oggi") ) { - @Notification.Body.Replace("Oggi", $"{Notification.StartDate:d}") +
@Notification.Body.Replace("Oggi", $"{Notification.StartDate:d}")
} else { - @Notification.Body +
@Notification.Body
} diff --git a/salesbook.Shared/Components/SingleElements/Card/NotificationCard.razor.css b/salesbook.Shared/Components/SingleElements/Card/NotificationCard.razor.css index 7c242b0..d62834a 100644 --- a/salesbook.Shared/Components/SingleElements/Card/NotificationCard.razor.css +++ b/salesbook.Shared/Components/SingleElements/Card/NotificationCard.razor.css @@ -105,4 +105,6 @@ .notification-body ::deep > .subtitle { font-size: 12px; color: var(--mud-palette-drawer-text); + line-height: inherit; + margin-top: .5rem; } \ No newline at end of file diff --git a/salesbook.Shared/Core/Dto/NotificationDataDTO.cs b/salesbook.Shared/Core/Dto/NotificationDataDTO.cs index 8e1537d..4379125 100644 --- a/salesbook.Shared/Core/Dto/NotificationDataDTO.cs +++ b/salesbook.Shared/Core/Dto/NotificationDataDTO.cs @@ -4,6 +4,9 @@ namespace salesbook.Shared.Core.Dto; public class NotificationDataDTO { + [JsonPropertyName("notificationId")] + public string? NotificationId { get; set; } + [JsonPropertyName("activityId")] public string? ActivityId { get; set; } diff --git a/salesbook.Shared/Core/Interface/IntegryApi/IIntegryNotificationRestClient.cs b/salesbook.Shared/Core/Interface/IntegryApi/IIntegryNotificationRestClient.cs index e396beb..19c8573 100644 --- a/salesbook.Shared/Core/Interface/IntegryApi/IIntegryNotificationRestClient.cs +++ b/salesbook.Shared/Core/Interface/IntegryApi/IIntegryNotificationRestClient.cs @@ -4,7 +4,7 @@ namespace salesbook.Shared.Core.Interface.IntegryApi; public interface IIntegryNotificationRestClient { - Task> Get(); + Task?> Get(); Task MarkAsRead(long id); Task Delete(long id); Task DeleteAll(); diff --git a/salesbook.Shared/Core/Services/IntegryNotificationRestClient.cs b/salesbook.Shared/Core/Services/IntegryNotificationRestClient.cs index 519c337..a415bfc 100644 --- a/salesbook.Shared/Core/Services/IntegryNotificationRestClient.cs +++ b/salesbook.Shared/Core/Services/IntegryNotificationRestClient.cs @@ -10,7 +10,7 @@ public class IntegryNotificationRestClient( IUserSession userSession, IIntegryApiRestClient integryApiRestClient) : IIntegryNotificationRestClient { - public Task> Get() + public Task?> Get() { var queryParams = new Dictionary { @@ -18,7 +18,7 @@ public class IntegryNotificationRestClient( { "forUser", userSession.User.Username } }; - return integryApiRestClient.Get>("notification", queryParams)!; + return integryApiRestClient.Get>("notification", queryParams); } public Task MarkAsRead(long id) => diff --git a/salesbook.Shared/Core/Services/NotificationService.cs b/salesbook.Shared/Core/Services/NotificationService.cs index 5814935..6d650b2 100644 --- a/salesbook.Shared/Core/Services/NotificationService.cs +++ b/salesbook.Shared/Core/Services/NotificationService.cs @@ -12,6 +12,8 @@ public class NotificationService( public async Task LoadNotification() { var allNotifications = await integryNotificationRestClient.Get(); + if (allNotifications == null) return; + var allIds = allNotifications.Select(n => n.Id).ToHashSet(); Notification.ReceivedNotifications = Notification.ReceivedNotifications diff --git a/salesbook.Shared/wwwroot/js/notifications.js b/salesbook.Shared/wwwroot/js/notifications.js index 6766874..6732fa8 100644 --- a/salesbook.Shared/wwwroot/js/notifications.js +++ b/salesbook.Shared/wwwroot/js/notifications.js @@ -145,13 +145,17 @@ function initRow(row) { } function removeRow(row) { - //collapseAndRemove(row); - dotnetHelper.invokeMethodAsync('Delete', row.id); + const id = row.id; + + collapseAndRemove(row); + dotnetHelper.invokeMethodAsync('Delete', id); } function markAsRead(row) { - //collapseAndRemove(row); - dotnetHelper.invokeMethodAsync('MarkAsRead', row.id); + const id = row.id; + + collapseAndRemove(row); + dotnetHelper.invokeMethodAsync('MarkAsRead', id); } function collapseAndRemove(row) { diff --git a/salesbook.Web/Core/Services/ManageDataService.cs b/salesbook.Web/Core/Services/ManageDataService.cs index b32c298..a9a1b8c 100644 --- a/salesbook.Web/Core/Services/ManageDataService.cs +++ b/salesbook.Web/Core/Services/ManageDataService.cs @@ -14,12 +14,12 @@ public class ManageDataService : IManageDataService throw new NotImplementedException(); } - public Task> GetClienti(WhereCondContact? whereCond) + public Task> GetClienti(WhereCondContact? whereCond = null) { throw new NotImplementedException(); } - public Task> GetProspect(WhereCondContact? whereCond) + public Task> GetProspect(WhereCondContact? whereCond = null) { throw new NotImplementedException(); } @@ -34,6 +34,11 @@ public class ManageDataService : IManageDataService throw new NotImplementedException(); } + public Task> GetActivityTryLocalDb(WhereCondActivity whereCond) + { + throw new NotImplementedException(); + } + public Task> GetActivity(WhereCondActivity whereCond, bool useLocalDb = false) { throw new NotImplementedException();