2015-07-22 05:16:11 +08:00
|
|
|
_ = require 'underscore'
|
|
|
|
React = require 'react'
|
|
|
|
|
2016-03-10 02:01:18 +08:00
|
|
|
{Actions,
|
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,
|
2016-03-10 02:01:18 +08:00
|
|
|
WorkspaceStore} = require 'nylas-exports'
|
2015-07-22 05:16:11 +08:00
|
|
|
|
2016-03-10 02:01:18 +08:00
|
|
|
{RetinaImg,
|
|
|
|
KeyCommandsRegion} = require 'nylas-component-kit'
|
|
|
|
|
|
|
|
CategoryPickerPopover = require './category-picker-popover'
|
2015-07-22 05:16:11 +08:00
|
|
|
|
2016-01-09 09:49:27 +08:00
|
|
|
|
2015-07-22 05:16:11 +08:00
|
|
|
# This changes the category on one or more threads.
|
|
|
|
class CategoryPicker extends React.Component
|
|
|
|
@displayName: "CategoryPicker"
|
2016-03-10 02:01:18 +08:00
|
|
|
|
2015-07-22 05:16:11 +08:00
|
|
|
@containerRequired: false
|
|
|
|
|
2016-03-10 02:01:18 +08:00
|
|
|
@propTypes:
|
|
|
|
thread: React.PropTypes.object
|
|
|
|
items: React.PropTypes.array
|
2015-07-22 05:16:11 +08:00
|
|
|
|
2015-07-24 02:47:46 +08:00
|
|
|
@contextTypes:
|
|
|
|
sheetDepth: React.PropTypes.number
|
|
|
|
|
2016-03-10 02:01:18 +08:00
|
|
|
constructor: (@props) ->
|
|
|
|
@_threads = @_getThreads(@props)
|
|
|
|
@_account = AccountStore.accountForItems(@_threads)
|
2016-01-09 09:49:27 +08:00
|
|
|
|
2016-01-09 01:31:24 +08:00
|
|
|
# If the threads we're picking categories for change, (like when they
|
|
|
|
# get their categories updated), we expect our parents to pass us new
|
|
|
|
# props. We don't listen to the DatabaseStore ourselves.
|
2015-07-22 05:16:11 +08:00
|
|
|
componentWillReceiveProps: (nextProps) ->
|
2016-03-10 02:01:18 +08:00
|
|
|
@_threads = @_getThreads(nextProps)
|
|
|
|
@_account = AccountStore.accountForItems(@_threads)
|
2016-01-09 09:49:27 +08:00
|
|
|
|
2016-03-10 02:01:18 +08:00
|
|
|
_getThreads: (props = @props) =>
|
|
|
|
if props.items then return (props.items ? [])
|
|
|
|
else if props.thread then return [props.thread]
|
|
|
|
else return []
|
2015-11-07 03:47:06 +08:00
|
|
|
|
|
|
|
_keymapHandlers: ->
|
|
|
|
"application:change-category": @_onOpenCategoryPopover
|
2015-07-22 05:16:11 +08:00
|
|
|
|
2015-07-24 02:47:46 +08:00
|
|
|
_onOpenCategoryPopover: =>
|
2016-03-10 02:01:18 +08:00
|
|
|
return unless @_threads.length > 0
|
2015-07-24 02:47:46 +08:00
|
|
|
return unless @context.sheetDepth is WorkspaceStore.sheetStack().length - 1
|
2016-03-10 02:01:18 +08:00
|
|
|
buttonRect = React.findDOMNode(@refs.button).getBoundingClientRect()
|
|
|
|
Actions.openPopover(
|
|
|
|
<CategoryPickerPopover
|
|
|
|
threads={@_threads}
|
|
|
|
account={@_account} />,
|
|
|
|
{originRect: buttonRect, direction: 'down'}
|
|
|
|
)
|
2015-07-24 02:47:46 +08:00
|
|
|
return
|
|
|
|
|
2016-03-10 02:01:18 +08:00
|
|
|
render: =>
|
|
|
|
return <span /> unless @_account
|
|
|
|
btnClasses = "btn btn-toolbar btn-category-picker"
|
|
|
|
img = ""
|
|
|
|
tooltip = ""
|
2015-12-03 03:43:37 +08:00
|
|
|
if @_account.usesLabels()
|
2016-03-10 02:01:18 +08:00
|
|
|
img = "toolbar-tag.png"
|
|
|
|
tooltip = "Apply Labels"
|
2015-12-03 03:43:37 +08:00
|
|
|
else
|
2016-03-10 02:01:18 +08:00
|
|
|
img = "toolbar-movetofolder.png"
|
|
|
|
tooltip = "Move to Folder"
|
2015-08-04 08:05:31 +08:00
|
|
|
|
2016-03-10 02:01:18 +08:00
|
|
|
return (
|
|
|
|
<KeyCommandsRegion style={order: -103} globalHandlers={@_keymapHandlers()}>
|
|
|
|
<button
|
|
|
|
ref="button"
|
|
|
|
title={tooltip}
|
|
|
|
onClick={@_onOpenCategoryPopover}
|
|
|
|
className={btnClasses} >
|
|
|
|
<RetinaImg name={img} mode={RetinaImg.Mode.ContentIsMask}/>
|
|
|
|
</button>
|
|
|
|
</KeyCommandsRegion>
|
|
|
|
)
|
2015-07-22 05:16:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
module.exports = CategoryPicker
|