2018-09-30 04:19:30 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { seafileAPI } from '../../utils/seafile-api';
|
2018-10-09 02:56:59 +00:00
|
|
|
import { gettext } from '../../utils/constants';
|
2018-09-30 04:19:30 +00:00
|
|
|
|
|
|
|
class Notification extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
showNotice: false,
|
2018-12-25 10:25:16 +00:00
|
|
|
notice_html: '',
|
|
|
|
unseenCount: 0,
|
2018-10-16 10:19:51 +00:00
|
|
|
};
|
2018-09-30 04:19:30 +00:00
|
|
|
}
|
|
|
|
|
2018-12-25 10:25:16 +00:00
|
|
|
componentDidMount() {
|
2018-12-25 10:47:12 +00:00
|
|
|
seafileAPI.getUnseenCount().then(res => {
|
|
|
|
this.setState({unseenCount: res.data.unseen_count});
|
|
|
|
});
|
2018-12-25 10:25:16 +00:00
|
|
|
}
|
|
|
|
|
2018-09-30 04:19:30 +00:00
|
|
|
onClick = () => {
|
|
|
|
if (this.state.showNotice) {
|
2018-10-16 10:19:51 +00:00
|
|
|
seafileAPI.updateNotifications();
|
2018-12-25 10:47:12 +00:00
|
|
|
this.setState({
|
|
|
|
showNotice: false,
|
|
|
|
unseenCount: 0
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
this.loadNotices();
|
|
|
|
this.setState({showNotice: true});
|
2018-09-30 04:19:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
loadNotices = () => {
|
|
|
|
seafileAPI.listPopupNotices().then(res => {
|
|
|
|
this.setState({
|
|
|
|
notice_html: res.data.notice_html
|
2018-10-16 10:19:51 +00:00
|
|
|
});
|
|
|
|
});
|
2018-09-30 04:19:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { notice_html } = this.state;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div id="notifications">
|
|
|
|
<a href="#" onClick={this.onClick} className="no-deco" id="notice-icon" title="Notifications" aria-label="Notifications">
|
|
|
|
<span className="sf2-icon-bell"></span>
|
2018-12-25 10:25:16 +00:00
|
|
|
<span className={`num ${this.state.unseenCount ? '' : 'hide'}`}>{this.state.unseenCount}</span>
|
2018-09-30 04:19:30 +00:00
|
|
|
</a>
|
|
|
|
<div id="notice-popover" className={`sf-popover ${this.state.showNotice ? '': 'hide'}`}>
|
|
|
|
<div className="outer-caret up-outer-caret"><div className="inner-caret"></div></div>
|
|
|
|
<div className="sf-popover-hd ovhd">
|
|
|
|
<h3 className="sf-popover-title title">{gettext('Notifications')}</h3>
|
|
|
|
<a href="#" onClick={this.onClick} title={gettext('Close')} aria-label={gettext('Close')} className="sf-popover-close js-close sf2-icon-x1 op-icon float-right"></a>
|
|
|
|
</div>
|
|
|
|
<div className="sf-popover-con">
|
2018-10-16 10:19:51 +00:00
|
|
|
<ul className="notice-list" dangerouslySetInnerHTML={{__html: notice_html}}></ul>
|
2018-09-30 04:19:30 +00:00
|
|
|
<a href="/notification/list/" className="view-all">{gettext('See All Notifications')}</a>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2018-10-16 10:19:51 +00:00
|
|
|
);
|
2018-09-30 04:19:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Notification;
|