Mailspring/app/internal_packages/message-list/lib/sidebar-plugin-container.jsx

81 lines
2 KiB
React
Raw Normal View History

2017-09-27 02:33:08 +08:00
import { React, PropTypes, FocusedContactsStore } from 'nylas-exports';
import { InjectedComponentSet } from 'nylas-component-kit';
class FocusedContactStorePropsContainer extends React.Component {
static displayName = 'FocusedContactStorePropsContainer';
constructor(props) {
super(props);
2017-09-27 02:33:08 +08:00
this.state = this._getStateFromStores();
}
componentDidMount() {
this.unsubscribe = FocusedContactsStore.listen(this._onChange);
}
componentWillUnmount() {
this.unsubscribe();
}
_onChange = () => {
this.setState(this._getStateFromStores());
2017-09-27 02:33:08 +08:00
};
_getStateFromStores() {
return {
sortedContacts: FocusedContactsStore.sortedContacts(),
focusedContact: FocusedContactsStore.focusedContact(),
focusedContactThreads: FocusedContactsStore.focusedContactThreads(),
};
}
render() {
2017-09-27 02:33:08 +08:00
let classname = 'sidebar-section';
let inner = null;
if (this.state.focusedContact) {
2017-09-27 02:33:08 +08:00
classname += ' visible';
inner = React.cloneElement(this.props.children, this.state);
}
2017-09-27 02:33:08 +08:00
return <div className={classname}>{inner}</div>;
}
}
2017-09-27 02:33:08 +08:00
const SidebarPluginContainerInner = props => {
return (
<InjectedComponentSet
className="sidebar-contact-card"
key={props.focusedContact.email}
2017-09-27 02:33:08 +08:00
matching={{ role: 'MessageListSidebar:ContactCard' }}
direction="column"
exposedProps={{
contact: props.focusedContact,
contactThreads: props.focusedContactThreads,
}}
/>
);
2017-09-27 02:33:08 +08:00
};
SidebarPluginContainerInner.propTypes = {
2017-09-27 02:33:08 +08:00
focusedContact: PropTypes.object,
focusedContactThreads: PropTypes.array,
};
export default class SidebarPluginContainer extends React.Component {
static displayName = 'SidebarPluginContainer';
static containerStyles = {
order: 1,
flexShrink: 0,
minWidth: 200,
maxWidth: 300,
};
render() {
return (
<FocusedContactStorePropsContainer>
<SidebarPluginContainerInner />
</FocusedContactStorePropsContainer>
);
}
}