Mailspring/internal_packages/preferences/lib/preferences.cjsx
Ben Gotow 607ca3bf10 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-21 15:29:58 -07:00

74 lines
2.1 KiB
CoffeeScript

React = require 'react'
_ = require 'underscore'
{RetinaImg, Flexbox} = require 'nylas-component-kit'
PreferencesStore = require './preferences-store'
PreferencesHeader = require './preferences-header'
class Preferences extends React.Component
@displayName: 'Preferences'
constructor: (@props) ->
@state = _.extend @getStateFromStores(),
activeTab: PreferencesStore.tabs()[0]
componentDidMount: =>
@unlisteners = []
@unlisteners.push PreferencesStore.listen =>
@setState(@getStateFromStores())
@unlisteners.push atom.config.observe null, (val) =>
@setState(@getStateFromStores())
componentWillUnmount: =>
unlisten() for unlisten in @unlisteners
componentDidUpdate: =>
if @state.tabs.length > 0 and not @state.activeTab
@setState(activeTab: @state.tabs[0])
getStateFromStores: =>
config: @getConfigWithMutators()
tabs: PreferencesStore.tabs()
getConfigWithMutators: =>
_.extend atom.config.get(), {
get: (key) =>
atom.config.get(key)
set: (key, value) =>
atom.config.set(key, value)
return
toggle: (key) =>
atom.config.set(key, !atom.config.get(key))
return
contains: (key, val) =>
vals = atom.config.get(key)
return false unless vals and vals instanceof Array
return val in vals
toggleContains: (key, val) =>
vals = atom.config.get(key)
vals = [] unless vals and vals instanceof Array
if val in vals
atom.config.set(key, _.without(vals, val))
else
atom.config.set(key, vals.concat([val]))
return
}
render: =>
if @state.activeTab
bodyElement = <@state.activeTab.component config={@state.config} />
else
bodyElement = <div>No Tab Active</div>
<div className="preferences-wrap">
<PreferencesHeader tabs={@state.tabs}
activeTab={@state.activeTab}
changeActiveTab={@_onChangeActiveTab}/>
{bodyElement}
<div style={clear:'both'}></div>
</div>
_onChangeActiveTab: (tab) =>
@setState(activeTab: tab)
module.exports = Preferences