React = require 'react/addons' ReactCSSTransitionGroup = React.addons.CSSTransitionGroup OnboardingActions = require './onboarding-actions' OnboardingStore = require './onboarding-store' querystring = require 'querystring' {EdgehillAPI} = require 'nylas-exports' {RetinaImg} = require 'nylas-component-kit' class ContainerView extends React.Component constructor: (@props) -> @state = @getStateFromStore() getStateFromStore: => page: OnboardingStore.page() error: OnboardingStore.error() environment: OnboardingStore.environment() connectType: OnboardingStore.connectType() componentDidMount: => @unsubscribe = OnboardingStore.listen(@_onStateChanged, @) # It's important that every React class explicitly stops listening to # atom events before it unmounts. Thank you event-kit # This can be fixed via a Reflux mixin componentWillUnmount: => @unsubscribe() if @unsubscribe componentDidUpdate: => webview = @refs['connect-iframe'] if webview node = React.findDOMNode(webview) if node.hasListeners is undefined # Remove as soon as possible. Initial src is not correctly loaded # on webview, and this fixes it. Electron 0.26.0 setTimeout -> node.src = node.src node.addEventListener 'new-window', (e) -> require('shell').openExternal(e.url) node.addEventListener 'did-start-loading', (e) -> if node.hasMobileUserAgent is undefined node.setUserAgent("Mozilla/5.0 (iPhone; CPU iPhone OS 7_1 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D167 Safari/9537.53") node.hasMobileUserAgent = true node.reload() node.addEventListener 'did-finish-load', (e) -> if node.getUrl().indexOf('/connect/complete') != -1 query = node.getUrl().split('?')[1] query = query[0..-2] if query[query.length - 1] is '#' token = querystring.decode(query) OnboardingActions.finishedConnect(token) if node.getUrl().indexOf('cancelled') != -1 OnboardingActions.moveToPreviousPage() render: => {@_pageComponent()}
_pageComponent: => if @state.error alert =
{@state.error}
else alert =
if @state.page is 'welcome'

Welcome to Nylas

Enter your email address:
{@_environmentComponent()}
else if @state.page == 'add-account'

Connect an Account

Link accounts from other services to supercharge your email.
else if @state.page == 'add-account-auth'
{ React.createElement('webview',{ "ref": "connect-iframe", "key": @state.page, "src": @_connectWebViewURL() }) }
else if @state.page == 'add-account-success' # http://codepen.io/stevenfabre/pen/NPWeVb
_environmentComponent: => return [] unless atom.inDevMode()
_connectWebViewURL: => EdgehillAPI.urlForConnecting(@state.connectType, @state.email) _onStateChanged: => @setState(@getStateFromStore()) _onValueChange: (event) => changes = {} changes[event.target.id] = event.target.value @setState(changes) _fireDismiss: => atom.close() _fireQuit: => require('ipc').send('command', 'application:quit') _fireSetEnvironment: (event) => OnboardingActions.setEnvironment(event.target.value) _fireStart: (e) => OnboardingActions.startConnect('inbox') _fireAuthAccount: (service) => OnboardingActions.startConnect(service) _fireMoveToPage: (page) => OnboardingActions.moveToPage(page) _fireMoveToPrevPage: => OnboardingActions.moveToPreviousPage() module.exports = ContainerView