Skip to content

Commit

Permalink
fix: mark a notification as read as soon as it is viewed (MetaMask#24765
Browse files Browse the repository at this point in the history
)
  • Loading branch information
matteoscurati authored May 24, 2024
1 parent 12e5784 commit 708822d
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions ui/pages/notification-details/notification-details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,41 +43,38 @@ export default function NotificationDetails() {
notificationData,
);

const { markNotificationAsRead } = useMarkNotificationAsRead();

useEffect(() => {
if (!id || !notificationData) {
redirectToNotifications();
}
if (notificationData) {
setNotification(notificationData);
// Mark the notification as read when the page is viewed
markNotificationAsRead([
{
id: notificationData.id,
type: notificationData.type,
isRead: notificationData.isRead,
},
]);
}
}, [id, notificationData]);
}, [id, notificationData, markNotificationAsRead]);

if (!notification) {
redirectToNotifications();
return null;
}

const { markNotificationAsRead } = useMarkNotificationAsRead();

const onClickBack = () => {
markNotificationAsRead([
{
id: notification.id,
type: notification.type,
isRead: notification.isRead,
},
]);
history.push(NOTIFICATIONS_ROUTE);
};

if (!hasNotificationComponents(notification.type)) {
return null;
}
const ncs = NotificationComponents[notification.type];

return (
<NotificationsPage>
<NotificationDetailsHeader onClickBack={onClickBack}>
<NotificationDetailsHeader onClickBack={redirectToNotifications}>
<ncs.details.title notification={notification} />
</NotificationDetailsHeader>
<Content padding={0}>
Expand Down

0 comments on commit 708822d

Please sign in to comment.