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-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: =>
|
2015-09-23 11:11:51 +08:00
|
|
|
atom.setSize(667,482)
|
2015-06-18 06:58:58 +08:00
|
|
|
@unsubscribe = PageRouterStore.listen(@_onStateChanged, @)
|
|
|
|
|
2015-09-23 11:11:51 +08:00
|
|
|
componentDidUpdate: =>
|
|
|
|
setTimeout( =>
|
|
|
|
@_resizePage()
|
|
|
|
,10)
|
|
|
|
|
|
|
|
_resizePage: =>
|
|
|
|
{width,height} = React.findDOMNode(@refs.container).getBoundingClientRect()
|
|
|
|
atom.setSizeAnimated(width,height)
|
|
|
|
|
2015-06-18 06:58:58 +08:00
|
|
|
_onStateChanged: => @setState(@_getStateFromStore())
|
|
|
|
|
|
|
|
componentWillUnmount: => @unsubscribe?()
|
|
|
|
|
|
|
|
render: =>
|
|
|
|
<div className="page-frame">
|
2015-09-23 11:11:51 +08:00
|
|
|
{@_renderDragRegion()}
|
|
|
|
<div
|
|
|
|
className="page-container"
|
|
|
|
ref="container"
|
|
|
|
transitionName="page"
|
|
|
|
leaveTimeout={150}
|
|
|
|
enterTimeout={150}>
|
2015-06-18 06:58:58 +08:00
|
|
|
{@_renderCurrentPage()}
|
2015-09-23 11:11:51 +08:00
|
|
|
</div>
|
|
|
|
{@_renderGradients()}
|
|
|
|
|
|
|
|
<div className="page-background" style={background: "#f6f7f8"}/>
|
2015-06-18 06:58:58 +08:00
|
|
|
</div>
|
|
|
|
|
2015-09-23 11:11:51 +08:00
|
|
|
_renderGradients: =>
|
|
|
|
gradient = @state.pageData?.provider?.color
|
|
|
|
if gradient
|
|
|
|
background = "linear-gradient(to top, #f6f7f8, #{gradient})"
|
|
|
|
else
|
|
|
|
background = "linear-gradient(to top, #f6f7f8 0%, rgba(255,255,255,0) 100%),
|
|
|
|
linear-gradient(to right, #e1e58f 0%, #a8d29e 50%, #8bc9c9 100%)"
|
|
|
|
|
|
|
|
<div className="page-gradient" style={background: background}/>
|
|
|
|
|
2015-06-18 06:58:58 +08:00
|
|
|
_renderCurrentPage: =>
|
|
|
|
switch @state.page
|
|
|
|
when "welcome"
|
2015-09-23 11:11:51 +08:00
|
|
|
<WelcomePage key="welcome" pageData={@state.pageData} />
|
|
|
|
when "account-choose"
|
|
|
|
<AccountChoosePage key="account-choose" pageData={@state.pageData} />
|
|
|
|
when "account-settings"
|
|
|
|
<AccountSettingsPage key="account-settings" pageData={@state.pageData} onResize={@_resizePage} />
|
|
|
|
when "initial-preferences"
|
|
|
|
<InitialPreferencesPage key="initial-preferences" pageData={@state.pageData} />
|
|
|
|
when "initial-packages"
|
|
|
|
<InitialPackagesPage key="initial-packages" pageData={@state.pageData} />
|
2015-06-18 06:58:58 +08:00
|
|
|
else
|
|
|
|
<div></div>
|
|
|
|
|
|
|
|
_renderDragRegion: ->
|
|
|
|
styles =
|
|
|
|
top:0
|
|
|
|
left:40
|
|
|
|
right:0
|
|
|
|
height: 20
|
|
|
|
zIndex:100
|
|
|
|
position: 'absolute'
|
|
|
|
"WebkitAppRegion": "drag"
|
|
|
|
<div className="dragRegion" style={styles}></div>
|
|
|
|
|
|
|
|
module.exports = PageRouter
|