Mailspring/examples/N1-Composer-Templates/lib/template-status-bar.jsx
Juan Tejada 647aed5f14 Convert Composer Template example to ES6
Summary:
- Include ES6 files in spec-suite
- Fix template store specs
- Refactors TemplateStore a little bit to adjust to specs
- Convert coffe .cjsx files to ES6 .jsx files
- Fix TemplateDraftStoreExtension functions
- Update ComposerTemplates example README

Test Plan: - Plugin unit tests

Reviewers: bengotow, evan

Reviewed By: evan

Differential Revision: https://phab.nylas.com/D2250
2015-11-14 22:12:06 -08:00

62 lines
1.4 KiB
JavaScript

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;