2015-08-01 04:12:47 +08:00
|
|
|
_ = require 'underscore'
|
|
|
|
path = require 'path'
|
|
|
|
React = require 'react'
|
|
|
|
classNames = require 'classnames'
|
|
|
|
{RetinaImg, TimeoutTransitionGroup} = require 'nylas-component-kit'
|
|
|
|
{Actions,
|
|
|
|
Utils,
|
|
|
|
ComponentRegistry,
|
|
|
|
UndoRedoStore,
|
feat(accounts): Kill namespaces, long live accounts
Summary:
This diff replaces the Namespace object with the Account object, and changes all references to namespace_id => account_id, etc. The endpoints are now `/threads` instead of `/n/<id>/threads`.
This diff also adds preliminary support for multiple accounts. When you log in, we now log you in to all the attached accounts on edgehill server. From the preferences panel, you can auth with / unlink additional accounts. Shockingly, this all seems to pretty much work.
When replying to a thread, you cannot switch from addresses. However, when creating a new message in a popout composer, you can change the from address and the SaveDraftTask will delete/re-root the draft on the new account.
Search bar doesn't need to do full refresh on clear if it never committed
Allow drafts to be switched to a different account when not in reply to an existing thread
Fix edge case where ChangeMailTask throws exception if no models are modified during performLocal
Show many dots for many accounts in long polling status bar
add/remove accounts from prefs
Spec fixes!
Test Plan: Run tests, none broken!
Reviewers: evan, dillon
Reviewed By: evan, dillon
Differential Revision: https://phab.nylas.com/D1928
2015-08-22 06:29:58 +08:00
|
|
|
AccountStore} = require 'nylas-exports'
|
2015-08-01 04:12:47 +08:00
|
|
|
|
|
|
|
class UndoRedoComponent extends React.Component
|
|
|
|
@displayName: 'UndoRedoComponent'
|
|
|
|
|
|
|
|
constructor: (@props) ->
|
|
|
|
@state = @_getStateFromStores()
|
|
|
|
@_timeout = null
|
|
|
|
|
|
|
|
_onChange: =>
|
|
|
|
@setState(@_getStateFromStores(), =>
|
|
|
|
@_setNewTimeout())
|
|
|
|
|
|
|
|
_clearTimeout: =>
|
|
|
|
clearTimeout(@_timeout)
|
|
|
|
|
|
|
|
_setNewTimeout: =>
|
2015-08-04 01:21:04 +08:00
|
|
|
@_clearTimeout()
|
2015-08-01 04:12:47 +08:00
|
|
|
@_timeout = setTimeout (=>
|
|
|
|
@_hide()
|
|
|
|
return
|
|
|
|
), 3000
|
|
|
|
|
|
|
|
_getStateFromStores: ->
|
2015-08-04 05:46:19 +08:00
|
|
|
task = UndoRedoStore.getMostRecentTask()
|
|
|
|
show = false
|
|
|
|
if task
|
|
|
|
show = true
|
2015-08-01 04:12:47 +08:00
|
|
|
|
2015-08-04 05:46:19 +08:00
|
|
|
return {show, task}
|
2015-08-01 04:12:47 +08:00
|
|
|
|
|
|
|
componentWillMount: ->
|
2015-08-04 01:21:04 +08:00
|
|
|
@_unsubscribe = UndoRedoStore.listen(@_onChange)
|
2015-08-01 04:12:47 +08:00
|
|
|
|
|
|
|
componentWillUnmount: ->
|
2015-08-04 01:21:04 +08:00
|
|
|
@_clearTimeout()
|
|
|
|
@_unsubscribe()
|
2015-08-01 04:12:47 +08:00
|
|
|
|
|
|
|
render: =>
|
2015-08-06 08:40:33 +08:00
|
|
|
inner = @_renderUndoRedoManager()
|
2015-08-01 04:12:47 +08:00
|
|
|
|
|
|
|
names = classNames
|
|
|
|
"undo-redo-manager": true
|
|
|
|
|
|
|
|
<TimeoutTransitionGroup
|
|
|
|
className={names}
|
|
|
|
leaveTimeout={450}
|
|
|
|
enterTimeout={250}
|
|
|
|
transitionName="undo-redo-item">
|
2015-08-06 08:40:33 +08:00
|
|
|
{inner}
|
2015-08-01 04:12:47 +08:00
|
|
|
</TimeoutTransitionGroup>
|
|
|
|
|
|
|
|
_renderUndoRedoManager: =>
|
|
|
|
if @state.show
|
|
|
|
<div className="undo-redo" onMouseEnter={@_clearTimeout} onMouseLeave={@_setNewTimeout}>
|
|
|
|
<div className="undo-redo-message-wrapper">
|
2015-08-04 05:46:19 +08:00
|
|
|
{@state.task.description()}
|
2015-08-01 04:12:47 +08:00
|
|
|
</div>
|
|
|
|
<div className="undo-redo-action-wrapper" onClick={@_undoTask}>
|
|
|
|
<RetinaImg name="undo-icon@2x.png"
|
|
|
|
mode={RetinaImg.Mode.ContentPreserve}/>
|
2015-08-04 05:46:19 +08:00
|
|
|
<span className="undo-redo-action-text">Undo</span>
|
2015-08-01 04:12:47 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
else
|
|
|
|
[]
|
|
|
|
|
|
|
|
_undoTask: =>
|
|
|
|
atom.commands.dispatch(document.querySelector('body'), 'core:undo')
|
|
|
|
@_hide()
|
|
|
|
|
|
|
|
_hide: =>
|
|
|
|
@setState({show: false, task: null})
|
|
|
|
|
|
|
|
module.exports = UndoRedoComponent
|