From 06948bb98b3e66aa8f715f3806023599c27d47ab Mon Sep 17 00:00:00 2001 From: Marshall Polaris Date: Mon, 25 Jul 2022 16:37:23 -0700 Subject: [PATCH] Make `setNotificationsAsSeen` return a promise (#692) --- web/pages/notifications.tsx | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/web/pages/notifications.tsx b/web/pages/notifications.tsx index 8076f71f..9f076c41 100644 --- a/web/pages/notifications.tsx +++ b/web/pages/notifications.tsx @@ -726,18 +726,14 @@ function NotificationItem(props: { ) } -export const setNotificationsAsSeen = (notifications: Notification[]) => { - notifications.forEach((notification) => { - if (!notification.isSeen) - updateDoc( - doc(db, `users/${notification.userId}/notifications/`, notification.id), - { - isSeen: true, - viewTime: new Date(), - } - ) - }) - return notifications +export const setNotificationsAsSeen = async (notifications: Notification[]) => { + const unseenNotifications = notifications.filter((n) => !n.isSeen) + return await Promise.all( + unseenNotifications.map((n) => { + const notificationDoc = doc(db, `users/${n.userId}/notifications/`, n.id) + return updateDoc(notificationDoc, { isSeen: true, viewTime: new Date() }) + }) + ) } function QuestionOrGroupLink(props: {