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
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: =>