NotificationsButton: re-fetch notification only when count > 0

This commit is contained in:
Jesse Chan
2020-11-10 20:56:18 +08:00
parent 971a54390f
commit 0d4a60f636

View File

@@ -71,7 +71,12 @@ class NotificationsButton extends Component<WrappedComponentProps, Notifications
constructor(props: WrappedComponentProps) {
super(props);
reaction(() => 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<WrappedComponentProps, Notifications
FloodActions.clearNotifications();
};
handleNotificationCountChange = () => {
if (this.tooltipRef != null && this.tooltipRef.isOpen()) {
this.fetchNotifications();
}
};
handleNewerNotificationsClick = () => {
if (this.state.paginationStart - NOTIFICATIONS_PER_PAGE >= 0) {
this.setState((state) => {