2015-10-30 05:20:41 +08:00
|
|
|
React = require 'react'
|
|
|
|
_ = require 'underscore'
|
|
|
|
{Contenteditable, RetinaImg, Flexbox} = require 'nylas-component-kit'
|
|
|
|
{AccountStore, Utils} = require 'nylas-exports'
|
|
|
|
|
|
|
|
class PreferencesSignatures extends React.Component
|
|
|
|
@displayName: 'PreferencesSignatures'
|
|
|
|
|
|
|
|
constructor: (@props) ->
|
|
|
|
@_signatureSaveQueue = {}
|
|
|
|
|
|
|
|
selectedAccountId = AccountStore.current()?.id
|
|
|
|
if selectedAccountId
|
|
|
|
key = @_configKey(selectedAccountId)
|
|
|
|
initialSig = @props.config.get(key)
|
|
|
|
else
|
|
|
|
initialSig = ""
|
|
|
|
|
|
|
|
@state =
|
2015-12-01 06:01:25 +08:00
|
|
|
editAsHTML: false
|
2015-10-30 05:20:41 +08:00
|
|
|
accounts: AccountStore.items()
|
|
|
|
currentSignature: initialSig
|
|
|
|
selectedAccountId: selectedAccountId
|
|
|
|
|
|
|
|
componentDidMount: ->
|
|
|
|
@usub = AccountStore.listen @_onChange
|
|
|
|
|
|
|
|
componentWillUnmount: ->
|
|
|
|
@usub()
|
|
|
|
@_saveSignatureNow(@state.selectedAccountId, @state.currentSignature)
|
|
|
|
|
|
|
|
_saveSignatureNow: (accountId, value) =>
|
|
|
|
key = @_configKey(accountId)
|
|
|
|
@props.config.set(key, value)
|
|
|
|
|
|
|
|
_saveSignatureSoon: (accountId, value) =>
|
|
|
|
@_signatureSaveQueue[accountId] = value
|
|
|
|
@_saveSignaturesFromCache()
|
|
|
|
|
|
|
|
__saveSignaturesFromCache: =>
|
|
|
|
for accountId, value of @_signatureSaveQueue
|
|
|
|
@_saveSignatureNow(accountId, value)
|
|
|
|
|
|
|
|
@_signatureSaveQueue = {}
|
|
|
|
|
|
|
|
_saveSignaturesFromCache: _.debounce(PreferencesSignatures::__saveSignaturesFromCache, 500)
|
|
|
|
|
|
|
|
_onChange: =>
|
|
|
|
@setState @_getStateFromStores()
|
|
|
|
|
|
|
|
_getStateFromStores: ->
|
|
|
|
accounts = AccountStore.items()
|
|
|
|
selectedAccountId = @state.selectedAccountId
|
|
|
|
currentSignature = @state.currentSignature
|
|
|
|
if not @state.selectedAccountId in _.pluck(accounts, "id")
|
|
|
|
selectedAccountId = null
|
|
|
|
currentSignature = ""
|
|
|
|
return {accounts, selectedAccountId, currentSignature}
|
|
|
|
|
|
|
|
_renderAccountPicker: ->
|
|
|
|
options = @state.accounts.map (account) ->
|
2015-12-01 09:11:57 +08:00
|
|
|
<option value={account.id} key={account.id}>{account.emailAddress}</option>
|
2015-10-30 05:20:41 +08:00
|
|
|
|
|
|
|
<select value={@state.selectedAccountId} onChange={@_onSelectAccount}>
|
|
|
|
{options}
|
|
|
|
</select>
|
|
|
|
|
2015-12-01 06:01:25 +08:00
|
|
|
_renderEditableSignature: ->
|
2015-10-30 05:20:41 +08:00
|
|
|
<Contenteditable
|
feat(mail-rules): Per-account mail rules filter incoming, existing mail
Summary:
Originally, this was going to be a totally independent package, but
I wasn't able to isolate the functionality and get it tied in to
the delta-stream consumption. Here's how it currently works:
- The preferences package has a new tab which allows you to edit
mail filters. Filters are saved in a new core store, and a new
stock component (ScenarioEditor) renders the editor. The editor
takes a set of templates that define a value space, and outputs
a valid set of values.
- A new MailFilterProcessor takes messages and creates tasks to
apply the actions from the MailFiltersStore.
- The worker-sync package now uses the MailFilterProcessor to
apply filters /before/ it calls didPassivelyReceiveNewModels,
so filtrs are applied before any notifications are created.
- A new task, ReprocessMailFiltersTask allows you to run filters
on all of your existing mail. It leverages the existing TaskQueue
architecture to: a) resume where it left off if you quit midway,
b) be queryable (for status) from all windows and c) cancelable.
The TaskQueue is a bit strange because it runs performLocal and
performRemote very differently, and I had to use `performRemote`.
(todo refactor soon.)
This diff also changes the EditableList a bit to behave like a
controlled component and render focused / unfocused states.
Test Plan: Run tests, only for actual filter processing atm.
Reviewers: juan, evan
Reviewed By: evan
Differential Revision: https://phab.nylas.com/D2379
2015-12-23 15:19:32 +08:00
|
|
|
tabIndex={-1}
|
2015-10-30 05:20:41 +08:00
|
|
|
ref="signatureInput"
|
2015-10-31 08:03:33 +08:00
|
|
|
value={@state.currentSignature}
|
2015-10-30 05:20:41 +08:00
|
|
|
onChange={@_onEditSignature}
|
2015-12-01 03:48:24 +08:00
|
|
|
spellcheck={false} />
|
2015-10-30 05:20:41 +08:00
|
|
|
|
2015-12-01 06:01:25 +08:00
|
|
|
_renderHTMLSignature: ->
|
|
|
|
<textarea ref="signatureHTMLInput"
|
|
|
|
value={@state.currentSignature}
|
|
|
|
onChange={@_onEditSignature}/>
|
|
|
|
|
2015-10-30 05:20:41 +08:00
|
|
|
_onEditSignature: (event) =>
|
|
|
|
html = event.target.value
|
|
|
|
@setState currentSignature: html
|
|
|
|
@_saveSignatureSoon(@state.selectedAccountId, html)
|
|
|
|
|
|
|
|
_configKey: (accountId) ->
|
|
|
|
"nylas.account-#{accountId}.signature"
|
|
|
|
|
|
|
|
_onSelectAccount: (event) =>
|
|
|
|
@_saveSignatureNow(@state.selectedAccountId, @state.currentSignature)
|
|
|
|
selectedAccountId = event.target.value
|
|
|
|
key = @_configKey(selectedAccountId)
|
|
|
|
initialSig = @props.config.get(key) ? ""
|
|
|
|
@setState
|
|
|
|
currentSignature: initialSig
|
|
|
|
selectedAccountId: selectedAccountId
|
|
|
|
|
2015-12-01 06:01:25 +08:00
|
|
|
_renderModeToggle: ->
|
|
|
|
if @state.editAsHTML
|
|
|
|
return <a onClick={=> @setState(editAsHTML: false); return}>Edit live preview</a>
|
|
|
|
else
|
|
|
|
return <a onClick={=> @setState(editAsHTML: true); return}>Edit raw HTML</a>
|
|
|
|
|
2015-10-30 05:20:41 +08:00
|
|
|
render: =>
|
2015-12-01 06:01:25 +08:00
|
|
|
rawText = if @state.editAsHTML then "Raw HTML " else ""
|
2015-12-01 06:26:11 +08:00
|
|
|
<section className="container-signatures">
|
|
|
|
<h2>Signatures</h2>
|
2015-10-30 05:20:41 +08:00
|
|
|
<div className="section-title">
|
2015-12-01 06:01:25 +08:00
|
|
|
{rawText}Signature for: {@_renderAccountPicker()}
|
2015-10-30 05:20:41 +08:00
|
|
|
</div>
|
2015-12-01 03:48:24 +08:00
|
|
|
<div className="signature-wrap">
|
2015-12-01 06:01:25 +08:00
|
|
|
{if @state.editAsHTML then @_renderHTMLSignature() else @_renderEditableSignature()}
|
2015-10-30 05:20:41 +08:00
|
|
|
</div>
|
2015-12-01 06:01:25 +08:00
|
|
|
<div className="toggle-mode" style={marginTop: "1em"}>{@_renderModeToggle()}</div>
|
2015-12-01 06:26:11 +08:00
|
|
|
</section>
|
2015-10-30 05:20:41 +08:00
|
|
|
|
|
|
|
module.exports = PreferencesSignatures
|