2015-06-18 06:58:58 +08:00
|
|
|
React = require 'react/addons'
|
|
|
|
OnboardingActions = require './onboarding-actions'
|
|
|
|
ReactCSSTransitionGroup = React.addons.CSSTransitionGroup
|
|
|
|
PageRouterStore = require './page-router-store'
|
|
|
|
|
2015-09-23 11:11:51 +08:00
|
|
|
WelcomePage = require './welcome-page'
|
|
|
|
AccountChoosePage = require './account-choose-page'
|
|
|
|
AccountSettingsPage = require './account-settings-page'
|
|
|
|
InitialPreferencesPage = require './initial-preferences-page'
|
|
|
|
InitialPackagesPage = require './initial-packages-page'
|
2015-10-05 07:49:41 +08:00
|
|
|
TokenAuthPage = require './token-auth-page'
|
|
|
|
|
2015-06-18 06:58:58 +08:00
|
|
|
|
|
|
|
class PageRouter extends React.Component
|
|
|
|
@displayName: 'PageRouter'
|
|
|
|
@containerRequired: false
|
|
|
|
|
|
|
|
constructor: (@props) ->
|
|
|
|
@state = @_getStateFromStore()
|
|
|
|
window.OnboardingActions = OnboardingActions
|
|
|
|
|
|
|
|
_getStateFromStore: =>
|
|
|
|
page: PageRouterStore.page()
|
|
|
|
pageData: PageRouterStore.pageData()
|
|
|
|
|
|
|
|
componentDidMount: =>
|
|
|
|
@unsubscribe = PageRouterStore.listen(@_onStateChanged, @)
|
2015-09-25 05:51:15 +08:00
|
|
|
setTimeout(@_initializeWindowSize, 10)
|
|
|
|
|
|
|
|
componentDidUpdate: =>
|
|
|
|
setTimeout(@_updateWindowSize, 10)
|
|
|
|
|
|
|
|
_initializeWindowSize: =>
|
|
|
|
return if @_unmounted
|
2015-09-24 00:59:34 +08:00
|
|
|
{width, height} = React.findDOMNode(@refs.activePage).getBoundingClientRect()
|
2015-11-12 02:25:11 +08:00
|
|
|
NylasEnv.setSize(width, height)
|
|
|
|
NylasEnv.center()
|
|
|
|
NylasEnv.show()
|
2015-06-18 06:58:58 +08:00
|
|
|
|
2015-09-25 05:51:15 +08:00
|
|
|
_updateWindowSize: =>
|
|
|
|
return if @_unmounted
|
2015-09-24 00:59:34 +08:00
|
|
|
{width, height} = React.findDOMNode(@refs.activePage).getBoundingClientRect()
|
2015-11-12 02:25:11 +08:00
|
|
|
NylasEnv.setSizeAnimated(width, height)
|
2015-09-23 11:11:51 +08:00
|
|
|
|
2015-09-25 05:51:15 +08:00
|
|
|
_onStateChanged: =>
|
|
|
|
@setState(@_getStateFromStore())
|
2015-06-18 06:58:58 +08:00
|
|
|
|
2015-09-25 05:51:15 +08:00
|
|
|
componentWillUnmount: =>
|
|
|
|
@_unmounted = true
|
|
|
|
@unsubscribe?()
|
2015-06-18 06:58:58 +08:00
|
|
|
|
|
|
|
render: =>
|
|
|
|
<div className="page-frame">
|
2015-09-23 11:11:51 +08:00
|
|
|
{@_renderDragRegion()}
|
2015-09-24 00:59:34 +08:00
|
|
|
<ReactCSSTransitionGroup
|
2015-10-05 07:49:41 +08:00
|
|
|
transitionName="alpha-fade"
|
2015-09-23 11:11:51 +08:00
|
|
|
leaveTimeout={150}
|
|
|
|
enterTimeout={150}>
|
2015-06-18 06:58:58 +08:00
|
|
|
{@_renderCurrentPage()}
|
2015-09-24 00:59:34 +08:00
|
|
|
{@_renderCurrentPageGradient()}
|
|
|
|
</ReactCSSTransitionGroup>
|
|
|
|
<div className="page-background" style={background: "#f6f7f8"}/>
|
2015-06-18 06:58:58 +08:00
|
|
|
</div>
|
|
|
|
|
2015-09-24 00:59:34 +08:00
|
|
|
_renderCurrentPageGradient: =>
|
2015-09-23 11:11:51 +08:00
|
|
|
gradient = @state.pageData?.provider?.color
|
|
|
|
if gradient
|
|
|
|
background = "linear-gradient(to top, #f6f7f8, #{gradient})"
|
2015-09-26 08:43:36 +08:00
|
|
|
height = 200
|
2015-09-23 11:11:51 +08:00
|
|
|
else
|
2015-09-26 08:43:36 +08:00
|
|
|
background = "linear-gradient(to top, #f6f7f8 0%, rgba(255,255,255,0) 100%), linear-gradient(to right, #e1e58f 0%, #a8d29e 50%, #8bc9c9 100%)"
|
|
|
|
height = 330
|
|
|
|
<div className="page-gradient" key={"#{@state.page}-gradient"} style={background: background, height: height}/>
|
2015-09-23 11:11:51 +08:00
|
|
|
|
2015-06-18 06:58:58 +08:00
|
|
|
_renderCurrentPage: =>
|
2015-09-24 00:59:34 +08:00
|
|
|
Component = {
|
|
|
|
"welcome": WelcomePage
|
2015-10-05 07:49:41 +08:00
|
|
|
"token-auth": TokenAuthPage
|
2015-09-24 00:59:34 +08:00
|
|
|
"account-choose": AccountChoosePage
|
|
|
|
"account-settings": AccountSettingsPage
|
|
|
|
"initial-preferences": InitialPreferencesPage
|
|
|
|
"initial-packages": InitialPackagesPage
|
|
|
|
}[@state.page]
|
|
|
|
|
|
|
|
<div key={@state.page} className="page-container">
|
2015-09-25 05:51:15 +08:00
|
|
|
<Component pageData={@state.pageData} ref="activePage" onResize={@_updateWindowSize}/>
|
2015-09-24 00:59:34 +08:00
|
|
|
</div>
|
2015-06-18 06:58:58 +08:00
|
|
|
|
|
|
|
_renderDragRegion: ->
|
|
|
|
styles =
|
|
|
|
top:0
|
2015-09-26 08:43:36 +08:00
|
|
|
left: 26
|
2015-06-18 06:58:58 +08:00
|
|
|
right:0
|
2015-09-26 08:43:36 +08:00
|
|
|
height: 27
|
2015-06-18 06:58:58 +08:00
|
|
|
zIndex:100
|
|
|
|
position: 'absolute'
|
|
|
|
"WebkitAppRegion": "drag"
|
|
|
|
<div className="dragRegion" style={styles}></div>
|
|
|
|
|
|
|
|
module.exports = PageRouter
|