Skip to content

Instantly share code, notes, and snippets.

@Retozi
Last active August 29, 2015 14:01
Show Gist options
  • Save Retozi/9c0abaf302dcfa6ab0bf to your computer and use it in GitHub Desktop.
Save Retozi/9c0abaf302dcfa6ab0bf to your computer and use it in GitHub Desktop.
AppRouter = Backbone.Router.extend({
routes: {
"entity/:id": "entity"
}
})
appRouter = new AppRouter()
Site = React.createClass({
componentWillMount: ->
Api.setLoginFunction((showLogin) => @setState({showLogin}))
appRouter.on('route:entity', @goToEntity)
Backbone.history.start({pushState: true})
componentWillUnmount: ->
Api.clearSetLoginFunction()
appRouter.off(null, null)
goToEntity: (id) ->
if window.innerWidth <= 1280
@setState({sidebarVisible: false})
@setUrlState(id, null, null, false)
setUrlState: (id, date, storyId, newsbarVisible) ->
@setState({
activeEntity: id
activeNewsDay: date
activeStory: storyId
})
if newsbarVisible then @showNewsbar() else @hideNewsbar()
getInitialState: -> {
activeEntity: null
activeNewsDay: null
activeStory: null
searchString: null
sidebarVisible: true
newsbarVisible: false
}
render: ->
R.div {
className: 'site-container',
'data-sidebar-is-visible': @state.sidebarVisible,
'data-newsbar-is-visible': @state.newsbarVisible
},
Header {}
Entity @makeProps()
Sidebar @makeProps()
Newsbar @makeProps()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment