Mailspring/app/internal_packages/activity/lib/list/activity-list-button.jsx

60 lines
1.5 KiB
React
Raw Normal View History

import React from 'react';
import { Actions, ReactDOM } from 'mailspring-exports';
2017-09-27 02:46:00 +08:00
import { RetinaImg } from 'mailspring-component-kit';
import ActivityList from './activity-list';
import ActivityEventStore from '../activity-event-store';
class ActivityListButton extends React.Component {
static displayName = 'ActivityListButton';
constructor() {
super();
this.state = this._getStateFromStores();
}
componentDidMount() {
this._unsub = ActivityEventStore.listen(this._onDataChanged);
}
componentWillUnmount() {
this._unsub();
}
onClick = () => {
const buttonRect = ReactDOM.findDOMNode(this).getBoundingClientRect();
2017-09-27 02:33:08 +08:00
Actions.openPopover(<ActivityList />, { originRect: buttonRect, direction: 'down' });
};
_onDataChanged = () => {
this.setState(this._getStateFromStores());
2017-09-27 02:33:08 +08:00
};
_getStateFromStores() {
return {
unreadCount: ActivityEventStore.unreadCount(),
2017-09-27 02:33:08 +08:00
};
}
render() {
2017-09-27 02:33:08 +08:00
let unreadCountClass = 'unread-count';
let iconClass = 'activity-toolbar-icon';
if (this.state.unreadCount) {
2017-09-27 02:33:08 +08:00
unreadCountClass += ' active';
iconClass += ' unread';
}
return (
2017-09-27 02:33:08 +08:00
<div tabIndex={-1} className="toolbar-activity" title="View activity" onClick={this.onClick}>
<div className={unreadCountClass}>{this.state.unreadCount}</div>
<RetinaImg
name="icon-toolbar-activity.png"
className={iconClass}
mode={RetinaImg.Mode.ContentIsMask}
/>
</div>
);
}
}
export default ActivityListButton;