From 0d4a60f636c7de8a84fbab7cd750576a85c00a79 Mon Sep 17 00:00:00 2001 From: Jesse Chan Date: Tue, 10 Nov 2020 20:56:18 +0800 Subject: [PATCH] NotificationsButton: re-fetch notification only when count > 0 --- .../components/sidebar/NotificationsButton.tsx | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/client/src/javascript/components/sidebar/NotificationsButton.tsx b/client/src/javascript/components/sidebar/NotificationsButton.tsx index 07fc3acf..1c8daf79 100644 --- a/client/src/javascript/components/sidebar/NotificationsButton.tsx +++ b/client/src/javascript/components/sidebar/NotificationsButton.tsx @@ -71,7 +71,12 @@ class NotificationsButton extends Component NotificationStore.notificationCount, this.handleNotificationCountChange); + reaction( + () => NotificationStore.notificationCount, + (count) => { + if (count.total > 0 && this.tooltipRef?.isOpen()) this.fetchNotifications(); + }, + ); this.state = { isLoading: false, @@ -225,12 +230,6 @@ class NotificationsButton extends Component { - if (this.tooltipRef != null && this.tooltipRef.isOpen()) { - this.fetchNotifications(); - } - }; - handleNewerNotificationsClick = () => { if (this.state.paginationStart - NOTIFICATIONS_PER_PAGE >= 0) { this.setState((state) => {