Run notifications panel stream in a Task + animations

This commit is contained in:
Thomas Ricouard 2023-01-29 18:05:00 +01:00
parent c748c935c9
commit 3a3ae87502
1 changed files with 14 additions and 10 deletions

View File

@ -116,6 +116,7 @@ class NotificationsViewModel: ObservableObject {
} }
func handleEvent(event: any StreamEvent) { func handleEvent(event: any StreamEvent) {
Task {
if let event = event as? StreamEventNotification, if let event = event as? StreamEventNotification,
!consolidatedNotifications.contains(where: { $0.id == event.notification.id }) !consolidatedNotifications.contains(where: { $0.id == event.notification.id })
{ {
@ -126,10 +127,13 @@ class NotificationsViewModel: ObservableObject {
notifications.insert(event.notification, at: 0) notifications.insert(event.notification, at: 0)
consolidatedNotifications = notifications.consolidated(selectedType: selectedType) consolidatedNotifications = notifications.consolidated(selectedType: selectedType)
} }
withAnimation {
state = .display(notifications: consolidatedNotifications, nextPageState: .hasNextPage) state = .display(notifications: consolidatedNotifications, nextPageState: .hasNextPage)
} }
} }
} }
}
}
struct ConsolidatedNotification: Identifiable { struct ConsolidatedNotification: Identifiable {
let notificationIds: [String] let notificationIds: [String]