From 801c7a4c3542a93d6c5f6343c73f73d6f7759fbc Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Wed, 30 Sep 2015 12:29:56 -0700 Subject: [PATCH] fix(account-switcher): Add Account > Manage Accounts --- .../account-sidebar/lib/account-switcher.cjsx | 8 ++--- internal_packages/preferences/lib/main.cjsx | 34 ++++++++++++------- .../preferences/lib/preferences.cjsx | 8 +++-- src/flux/actions.coffee | 8 +++++ src/react-remote/react-remote-parent.js | 2 +- 5 files changed, 40 insertions(+), 20 deletions(-) diff --git a/internal_packages/account-sidebar/lib/account-switcher.cjsx b/internal_packages/account-sidebar/lib/account-switcher.cjsx index cbf5fd392..8f160be3a 100644 --- a/internal_packages/account-sidebar/lib/account-switcher.cjsx +++ b/internal_packages/account-sidebar/lib/account-switcher.cjsx @@ -63,7 +63,7 @@ class AccountSwitcher extends React.Component _renderNewAccountOption: =>
- Add account… + Manage accounts…
@@ -114,8 +114,8 @@ class AccountSwitcher extends React.Component Actions.selectAccountId(account.id) @setState(showing: false) - _onAddAccount: => - require('ipc').send('command', 'application:add-account') + _onManageAccounts: => + Actions.openPreferences({tab: 'Accounts'}) @setState(showing: false) _getStateFromStores: => diff --git a/internal_packages/preferences/lib/main.cjsx b/internal_packages/preferences/lib/main.cjsx index d185e6a21..c7d2591e3 100644 --- a/internal_packages/preferences/lib/main.cjsx +++ b/internal_packages/preferences/lib/main.cjsx @@ -1,11 +1,10 @@ +PreferencesStore = require './preferences-store' + module.exports = activate: (@state={}) -> ipc = require 'ipc' React = require 'react' - Preferences = require('./preferences') - - {ReactRemote, - Actions} = require('nylas-exports') + {Actions} = require('nylas-exports') Actions.registerPreferencesTab({ icon: 'ic-settings-general.png' @@ -37,21 +36,30 @@ module.exports = name: 'Appearance' component: require './tabs/preferences-appearance' }) + # Actions.registerPreferencesTab({ # icon: 'ic-settings-signatures.png' # name: 'Signatures' # component: require './tabs/preferences-signatures' # }) - ipc.on 'open-preferences', (detail) -> - ReactRemote.openWindowForComponent(Preferences, { - tag: 'preferences' - title: "Preferences" - width: 520 - resizable: false - autosize: true - stylesheetRegex: /preferences/ - }) + Actions.openPreferences.listen(@_openPreferences) + ipc.on 'open-preferences', => @_openPreferences() + + _openPreferences: ({tab} = {}) -> + {ReactRemote} = require('nylas-exports') + Preferences = require('./preferences') + ReactRemote.openWindowForComponent(Preferences, { + tag: 'preferences' + title: "Preferences" + width: 520 + resizable: false + autosize: true + stylesheetRegex: /preferences/ + props: { + initialTab: tab + } + }) deactivate: -> diff --git a/internal_packages/preferences/lib/preferences.cjsx b/internal_packages/preferences/lib/preferences.cjsx index 252defb1b..47f42157c 100644 --- a/internal_packages/preferences/lib/preferences.cjsx +++ b/internal_packages/preferences/lib/preferences.cjsx @@ -9,8 +9,12 @@ class Preferences extends React.Component @displayName: 'Preferences' constructor: (@props) -> - @state = _.extend @getStateFromStores(), - activeTab: PreferencesStore.tabs()[0] + tabs = PreferencesStore.tabs() + if @props.initialTab + activeTab = _.find tabs, (t) => t.name is @props.initialTab + activeTab ||= tabs[0] + + @state = _.extend(@getStateFromStores(), {activeTab}) componentDidMount: => @unlisteners = [] diff --git a/src/flux/actions.coffee b/src/flux/actions.coffee index af62da8d6..877efa1e8 100644 --- a/src/flux/actions.coffee +++ b/src/flux/actions.coffee @@ -125,6 +125,14 @@ class Actions ### @retryInitialSync: ActionScopeWorkWindow + ### + Public: Open the preferences window. Pass an object with a tab name + (ie: `{tab: 'Accounts'}`) to open a specific panel. + + *Scope: Window* + ### + @openPreferences: ActionScopeWindow + ### Public: Register a preferences tab, usually applied in Preferences window diff --git a/src/react-remote/react-remote-parent.js b/src/react-remote/react-remote-parent.js index b28a15c8a..42626a216 100644 --- a/src/react-remote/react-remote-parent.js +++ b/src/react-remote/react-remote-parent.js @@ -340,7 +340,7 @@ var openWindowForComponent = function(Component, options) { // the browser window. When both of these things finish, we send the html // css, and any observed method invocations that occurred during the first // React cycle (componentDidMount). - React.render(React.createElement(Component), container, function() { + React.render(React.createElement(Component, options.props), container, function() { target.reactid = container.firstChild.dataset.reactid, target.containerReady = true; target.sendHTMLIfReady();