2018-01-31 09:40:32 +00:00
|
|
|
import React from 'react'
|
|
|
|
import { bindActionCreators } from 'redux'
|
|
|
|
import {
|
|
|
|
initStore,
|
|
|
|
startClock,
|
|
|
|
addCount,
|
|
|
|
serverRenderClock
|
|
|
|
} from '../lib/store'
|
|
|
|
import withRedux from 'next-redux-wrapper'
|
2017-12-27 18:57:57 +00:00
|
|
|
|
2017-03-30 18:21:13 +00:00
|
|
|
import App from '../components/App'
|
|
|
|
import Header from '../components/Header'
|
2018-01-31 09:40:32 +00:00
|
|
|
import Page from '../components/Page'
|
|
|
|
import Submit from '../components/Submit'
|
|
|
|
import PostList from '../components/PostList'
|
|
|
|
import withApollo from '../lib/withApollo'
|
2017-03-30 18:21:13 +00:00
|
|
|
|
2018-01-31 09:40:32 +00:00
|
|
|
class Index extends React.Component {
|
|
|
|
static getInitialProps ({ store, isServer }) {
|
|
|
|
store.dispatch(serverRenderClock(isServer))
|
|
|
|
store.dispatch(addCount())
|
|
|
|
|
|
|
|
return { isServer }
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
this.timer = this.props.startClock()
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount () {
|
|
|
|
clearInterval(this.timer)
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<App>
|
|
|
|
<Header />
|
|
|
|
<Page title='Index' />
|
|
|
|
<Submit />
|
|
|
|
<PostList />
|
|
|
|
</App>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
return {
|
|
|
|
addCount: bindActionCreators(addCount, dispatch),
|
|
|
|
startClock: bindActionCreators(startClock, dispatch)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-25 15:40:25 +00:00
|
|
|
export default withApollo(
|
|
|
|
withRedux(initStore, null, mapDispatchToProps)(Index)
|
2018-01-31 09:40:32 +00:00
|
|
|
)
|