mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-14 05:41:05 +08:00
afbcfb6853
Switch from manually setting containerRequired to false on each individual notification to setting it on the InjectedComponentSet within the notifs-wrapper. This way, people adding new notifications don't need to remember to manually set it themselves.
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
import _ from 'underscore';
|
|
import {React, ReactDOM} from 'nylas-exports'
|
|
import {InjectedComponentSet} from 'nylas-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}
|
|
/>
|
|
)
|
|
}
|
|
}
|