2017-11-13 19:37:43 +00:00
|
|
|
import React from 'react'
|
|
|
|
import Link from 'next/link'
|
|
|
|
import withRedux from 'next-redux-wrapper'
|
2018-02-04 11:56:32 +00:00
|
|
|
import initStore from '../redux'
|
2017-11-13 19:37:43 +00:00
|
|
|
import CharacterInfo from '../components/CharacterInfo'
|
2018-02-04 11:56:32 +00:00
|
|
|
import { rootEpic } from '../redux/epics'
|
|
|
|
import * as actions from '../redux/actions'
|
|
|
|
import { of } from 'rxjs/observable/of'
|
2017-11-13 19:37:43 +00:00
|
|
|
|
|
|
|
class Counter extends React.Component {
|
|
|
|
static async getInitialProps ({ store, isServer }) {
|
2018-02-04 11:56:32 +00:00
|
|
|
const resultAction = await rootEpic(
|
|
|
|
of(actions.fetchCharacter(isServer)),
|
|
|
|
store
|
|
|
|
).toPromise() // we need to convert Observable to Promise
|
2017-11-13 19:37:43 +00:00
|
|
|
store.dispatch(resultAction)
|
|
|
|
|
|
|
|
return { isServer }
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount () {
|
|
|
|
this.props.startFetchingCharacters()
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount () {
|
|
|
|
this.props.stopFetchingCharacters()
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<h1>Index Page</h1>
|
|
|
|
<CharacterInfo />
|
|
|
|
<br />
|
|
|
|
<nav>
|
|
|
|
<Link href='/other'><a>Navigate to "/other"</a></Link>
|
|
|
|
</nav>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default withRedux(
|
|
|
|
initStore,
|
|
|
|
null,
|
|
|
|
{
|
2018-02-04 11:56:32 +00:00
|
|
|
startFetchingCharacters: actions.startFetchingCharacters,
|
|
|
|
stopFetchingCharacters: actions.stopFetchingCharacters
|
2018-03-27 18:11:03 +00:00
|
|
|
}
|
2017-11-13 19:37:43 +00:00
|
|
|
)(Counter)
|