2015-07-16 23:54:20 +08:00
|
|
|
React = require 'react'
|
|
|
|
classNames = require 'classnames'
|
2015-07-24 02:10:51 +08:00
|
|
|
{Actions,
|
|
|
|
Utils,
|
|
|
|
UnreadCountStore,
|
|
|
|
WorkspaceStore,
|
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,
|
2015-07-24 02:10:51 +08:00
|
|
|
FocusedCategoryStore,
|
|
|
|
ChangeLabelsTask,
|
|
|
|
ChangeFolderTask,
|
|
|
|
CategoryStore} = require 'nylas-exports'
|
|
|
|
{RetinaImg, DropZone} = require 'nylas-component-kit'
|
2015-07-16 23:54:20 +08:00
|
|
|
|
|
|
|
class AccountSidebarCategoryItem extends React.Component
|
|
|
|
@displayName: 'AccountSidebarCategoryItem'
|
|
|
|
|
|
|
|
constructor: (@props) ->
|
|
|
|
@state =
|
|
|
|
unreadCount: UnreadCountStore.count() ? 0
|
|
|
|
|
|
|
|
componentWillMount: =>
|
|
|
|
@_usub = UnreadCountStore.listen @_onUnreadCountChange
|
|
|
|
|
|
|
|
componentWillUnmount: =>
|
|
|
|
@_usub()
|
|
|
|
|
|
|
|
_onUnreadCountChange: =>
|
|
|
|
@setState unreadCount: UnreadCountStore.count()
|
|
|
|
|
2015-07-24 02:10:51 +08:00
|
|
|
shouldComponentUpdate: (nextProps, nextState) =>
|
|
|
|
!Utils.isEqualReact(@props, nextProps) or !Utils.isEqualReact(@state, nextState)
|
2015-07-16 23:54:20 +08:00
|
|
|
|
|
|
|
render: =>
|
|
|
|
unread = []
|
|
|
|
if @props.item.name is "inbox" and @state.unreadCount > 0
|
|
|
|
unread = <div className="unread item-count-box">{@state.unreadCount}</div>
|
|
|
|
|
|
|
|
containerClass = classNames
|
|
|
|
'item': true
|
|
|
|
'selected': @props.select
|
2015-07-24 02:10:51 +08:00
|
|
|
'dropping': @state.isDropping
|
2015-07-16 23:54:20 +08:00
|
|
|
|
2015-07-24 02:10:51 +08:00
|
|
|
<DropZone className={containerClass}
|
|
|
|
onClick={@_onClick}
|
|
|
|
id={@props.item.id}
|
|
|
|
shouldAcceptDrop={@_shouldAcceptDrop}
|
|
|
|
onDragStateChange={ ({isDropping}) => @setState({isDropping}) }
|
|
|
|
onDrop={@_onDrop}>
|
2015-07-16 23:54:20 +08:00
|
|
|
{unread}
|
2015-07-24 03:33:21 +08:00
|
|
|
|
2015-09-01 01:47:25 +08:00
|
|
|
<div className="icon">{@_renderIcon()}</div>
|
|
|
|
<div className="name">{@props.item.displayName}</div>
|
2015-07-24 02:10:51 +08:00
|
|
|
</DropZone>
|
|
|
|
|
2015-07-24 03:33:21 +08:00
|
|
|
_renderIcon: ->
|
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
|
|
|
if @props.sectionType is "category" and AccountStore.current()
|
|
|
|
if AccountStore.current().usesLabels()
|
2015-07-24 03:33:21 +08:00
|
|
|
<RetinaImg name={"tag.png"} mode={RetinaImg.Mode.ContentIsMask} />
|
|
|
|
else
|
|
|
|
<RetinaImg name={"folder.png"} mode={RetinaImg.Mode.ContentIsMask} />
|
|
|
|
else if @props.sectionType is "mailboxes"
|
|
|
|
<RetinaImg name={"#{@props.item.name}.png"} fallback={'folder.png'} mode={RetinaImg.Mode.ContentIsMask} />
|
|
|
|
|
2015-07-24 02:10:51 +08:00
|
|
|
_shouldAcceptDrop: (e) =>
|
|
|
|
return false if @props.item.name in CategoryStore.LockedCategoryNames
|
|
|
|
return false if @props.item.name is FocusedCategoryStore.categoryName()
|
|
|
|
'nylas-thread-ids' in e.dataTransfer.types
|
|
|
|
|
|
|
|
_onDrop: (e) =>
|
|
|
|
jsonString = e.dataTransfer.getData('nylas-thread-ids')
|
|
|
|
try
|
|
|
|
ids = JSON.parse(jsonString)
|
|
|
|
catch err
|
|
|
|
console.error("AccountSidebarCategoryItem onDrop: JSON parse #{err}")
|
|
|
|
return unless ids
|
|
|
|
|
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
|
|
|
if AccountStore.current().usesLabels()
|
2015-07-24 02:10:51 +08:00
|
|
|
currentLabel = FocusedCategoryStore.category()
|
|
|
|
if currentLabel and not (currentLabel in CategoryStore.LockedCategoryNames)
|
|
|
|
labelsToRemove = [currentLabel]
|
|
|
|
|
|
|
|
task = new ChangeLabelsTask
|
2015-08-06 06:53:08 +08:00
|
|
|
threads: ids,
|
2015-07-24 02:10:51 +08:00
|
|
|
labelsToAdd: [@props.item],
|
|
|
|
labelsToRemove: labelsToRemove
|
|
|
|
else
|
|
|
|
task = new ChangeFolderTask
|
2015-08-06 06:53:08 +08:00
|
|
|
folder: @props.item,
|
|
|
|
threads: ids
|
2015-07-24 02:10:51 +08:00
|
|
|
|
|
|
|
Actions.queueTask(task)
|
2015-07-16 23:54:20 +08:00
|
|
|
|
|
|
|
_onClick: (event) =>
|
|
|
|
event.preventDefault()
|
|
|
|
Actions.selectRootSheet(WorkspaceStore.Sheet.Threads)
|
|
|
|
Actions.focusCategory(@props.item)
|
|
|
|
|
|
|
|
module.exports = AccountSidebarCategoryItem
|