React = require 'react/addons'
ReactCSSTransitionGroup = React.addons.CSSTransitionGroup
OnboardingActions = require './onboarding-actions'
OnboardingStore = require './onboarding-store'
querystring = require 'querystring'
{EdgehillAPI} = require 'inbox-exports'
{RetinaImg} = require 'ui-components'
module.exports =
ContainerView = React.createClass
getInitialState: ->
@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 = this.refs['connect-iframe']
if webview
node = webview.getDOMNode()
if node.hasListeners is undefined
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]
token = querystring.decode(query)
OnboardingActions.finishedConnect(token)
render: ->