import React from 'react'; import _ from 'underscore'; import { Flexbox, RetinaImg, EditableList, Contenteditable, ScrollRegion, MultiselectDropdown, } from 'nylas-component-kit'; import {AccountStore, SignatureStore, Actions} from 'nylas-exports'; export default class PreferencesSignatures extends React.Component { static displayName = 'PreferencesSignatures'; constructor() { super() this.state = this._getStateFromStores() } componentDidMount() { this.unsubscribers = [ SignatureStore.listen(this._onChange), ] } componentWillUnmount() { this.unsubscribers.forEach(unsubscribe => unsubscribe()); } _onChange = () => { this.setState(this._getStateFromStores()) } _getStateFromStores() { const signatures = SignatureStore.getSignatures() const accountsAndAliases = AccountStore.aliases() const selected = SignatureStore.selectedSignature() const defaults = SignatureStore.getDefaults() return { signatures: signatures, selectedSignature: selected, defaults: defaults, accountsAndAliases: accountsAndAliases, editAsHTML: this.state ? this.state.editAsHTML : false, } } _onCreateButtonClick = () => { this._onAddSignature() } _onAddSignature = () => { Actions.addSignature() } _onDeleteSignature = (signature) => { Actions.removeSignature(signature) } _onEditSignature = (edit) => { let editedSig; if (typeof edit === "object") { editedSig = { title: this.state.selectedSignature.title, body: edit.target.value, } } else { editedSig = { title: edit, body: this.state.selectedSignature.body, } } Actions.updateSignature(editedSig, this.state.selectedSignature.id) } _onSelectSignature = (sig) => { Actions.selectSignature(sig.id) } _onToggleAccount = (account) => { Actions.toggleAccount(account.email) } _onToggleEditAsHTML = () => { const toggled = !this.state.editAsHTML this.setState({editAsHTML: toggled}) } _renderListItemContent = (sig) => { return sig.title } _renderSignatureToolbar() { return (