diff --git a/frontend/src/components/common/notification.js b/frontend/src/components/common/notification.js index e80247b6cf..1ca7f29dc4 100644 --- a/frontend/src/components/common/notification.js +++ b/frontend/src/components/common/notification.js @@ -13,30 +13,24 @@ class Notification extends React.Component { } componentDidMount() { - this.loadUnseenCount(); - } - - onClick = () => { - this.setState({ - showNotice: !this.state.showNotice - }); - - if (!this.state.showNotice) { - this.loadNotices(); - } - - if (this.state.showNotice) { - seafileAPI.updateNotifications(); - this.loadUnseenCount(); - } - } - - loadUnseenCount = () => { seafileAPI.getUnseenCount().then(res => { this.setState({unseenCount: res.data.unseen_count}); }); } + onClick = () => { + if (this.state.showNotice) { + seafileAPI.updateNotifications(); + this.setState({ + showNotice: false, + unseenCount: 0 + }) + } else { + this.loadNotices(); + this.setState({showNotice: true}); + } + } + loadNotices = () => { seafileAPI.listPopupNotices().then(res => { this.setState({