mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-14 13:44:41 +08:00
51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
import _ from 'underscore';
|
|
import { React, ReactDOM } from 'mailspring-exports';
|
|
import { InjectedComponentSet } from 'mailspring-component-kit';
|
|
|
|
const ROLE = 'RootSidebar:Notifications';
|
|
|
|
export default class NotifWrapper extends React.Component {
|
|
static displayName = 'NotifWrapper';
|
|
|
|
componentDidMount() {
|
|
this.observer = new MutationObserver(this.update);
|
|
this.observer.observe(ReactDOM.findDOMNode(this), { childList: true });
|
|
this.update(); // Necessary if notifications are already mounted
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
this.observer.disconnect();
|
|
}
|
|
|
|
update = () => {
|
|
const className = 'highest-priority';
|
|
const node = ReactDOM.findDOMNode(this);
|
|
|
|
const oldHighestPriorityElems = node.querySelectorAll(`.${className}`);
|
|
for (const oldElem of oldHighestPriorityElems) {
|
|
oldElem.classList.remove(className);
|
|
}
|
|
|
|
const elemsWithPriority = node.querySelectorAll('[data-priority]');
|
|
if (elemsWithPriority.length === 0) {
|
|
return;
|
|
}
|
|
|
|
const highestPriorityElem = _.max(elemsWithPriority, elem =>
|
|
parseInt(elem.dataset.priority, 10)
|
|
);
|
|
|
|
highestPriorityElem.classList.add(className);
|
|
};
|
|
|
|
render() {
|
|
return (
|
|
<InjectedComponentSet
|
|
className="notifications"
|
|
matching={{ role: ROLE }}
|
|
direction="column"
|
|
containersRequired={false}
|
|
/>
|
|
);
|
|
}
|
|
}
|