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: =>
|
|
|
|
@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()
|
|
|
|
atom.center()
|
|
|
|
atom.setSizeAnimated(width, height, 0)
|
|
|
|
atom.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()
|
|
|
|
atom.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-09-23 11:11:51 +08:00
|
|
|
transitionName="page"
|
|
|
|
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})"
|
|
|
|
else
|
|
|
|
background = "linear-gradient(to top, #f6f7f8 0%, rgba(255,255,255,0) 100%),
|
|
|
|
linear-gradient(to right, #e1e58f 0%, #a8d29e 50%, #8bc9c9 100%)"
|
|
|
|
|
2015-09-24 00:59:34 +08:00
|
|
|
<div className="page-gradient" key={"#{@state.page}-gradient"} style={background: background}/>
|
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
|
|
|
|
"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
|
|
|
|
left:40
|
|
|
|
right:0
|
|
|
|
height: 20
|
|
|
|
zIndex:100
|
|
|
|
position: 'absolute'
|
|
|
|
"WebkitAppRegion": "drag"
|
|
|
|
<div className="dragRegion" style={styles}></div>
|
|
|
|
|
|
|
|
module.exports = PageRouter
|