From 3a3ae875028aeca6bf5ab0f4988fd72422c1ca1f Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Sun, 29 Jan 2023 18:05:00 +0100 Subject: [PATCH] Run notifications panel stream in a Task + animations --- .../NotificationsViewModel.swift | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/Packages/Notifications/Sources/Notifications/NotificationsViewModel.swift b/Packages/Notifications/Sources/Notifications/NotificationsViewModel.swift index 603a1e6a..ea616d91 100644 --- a/Packages/Notifications/Sources/Notifications/NotificationsViewModel.swift +++ b/Packages/Notifications/Sources/Notifications/NotificationsViewModel.swift @@ -116,17 +116,21 @@ class NotificationsViewModel: ObservableObject { } func handleEvent(event: any StreamEvent) { - if let event = event as? StreamEventNotification, - !consolidatedNotifications.contains(where: { $0.id == event.notification.id }) - { - if let selectedType, event.notification.type == selectedType.rawValue { - notifications.insert(event.notification, at: 0) - consolidatedNotifications = notifications.consolidated(selectedType: selectedType) - } else if selectedType == nil { - notifications.insert(event.notification, at: 0) - consolidatedNotifications = notifications.consolidated(selectedType: selectedType) + Task { + if let event = event as? StreamEventNotification, + !consolidatedNotifications.contains(where: { $0.id == event.notification.id }) + { + if let selectedType, event.notification.type == selectedType.rawValue { + notifications.insert(event.notification, at: 0) + consolidatedNotifications = notifications.consolidated(selectedType: selectedType) + } else if selectedType == nil { + notifications.insert(event.notification, at: 0) + consolidatedNotifications = notifications.consolidated(selectedType: selectedType) + } + withAnimation { + state = .display(notifications: consolidatedNotifications, nextPageState: .hasNextPage) + } } - state = .display(notifications: consolidatedNotifications, nextPageState: .hasNextPage) } } }