mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-11-14 13:44:41 +08:00
63 lines
1.4 KiB
React
63 lines
1.4 KiB
React
|
import {DraftStore, React} from 'nylas-exports';
|
||
|
|
||
|
class TemplateStatusBar extends React.Component {
|
||
|
static displayName = 'TemplateStatusBar'
|
||
|
|
||
|
static propTypes = {
|
||
|
draftClientId: React.PropTypes.string,
|
||
|
}
|
||
|
|
||
|
constructor() {
|
||
|
super();
|
||
|
this.state = { draft: null };
|
||
|
}
|
||
|
|
||
|
componentDidMount() {
|
||
|
DraftStore.sessionForClientId(this.props.draftClientId).then((_proxy)=> {
|
||
|
if (this._unmounted) {
|
||
|
return;
|
||
|
}
|
||
|
if (_proxy.draftClientId === this.props.draftClientId) {
|
||
|
this._proxy = _proxy;
|
||
|
this.unsubscribe = this._proxy.listen(this._onDraftChange.bind(this), this);
|
||
|
this._onDraftChange();
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
componentWillUnmount() {
|
||
|
this._unmounted = true;
|
||
|
if (this.unsubscribe) this.unsubscribe();
|
||
|
}
|
||
|
|
||
|
static containerStyles = {
|
||
|
textAlign: 'center',
|
||
|
width: 530,
|
||
|
margin: 'auto',
|
||
|
}
|
||
|
|
||
|
_onDraftChange() {
|
||
|
this.setState({draft: this._proxy.draft()});
|
||
|
}
|
||
|
|
||
|
_draftUsesTemplate() {
|
||
|
if (this.state.draft) {
|
||
|
return this.state.draft.body.search(/<code[^>]*class="var[^>]*>/i) > 0;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
render() {
|
||
|
if (this._draftUsesTemplate()) {
|
||
|
return (
|
||
|
<div className="template-status-bar">
|
||
|
Press "tab" to quickly fill in the blanks - highlighting will not be visible to recipients.
|
||
|
</div>
|
||
|
);
|
||
|
}
|
||
|
return <div></div>;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
export default TemplateStatusBar;
|