-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
70 lines (61 loc) · 1.97 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import React from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import Helmet from 'react-helmet';
import { showHello, showHelloAsync, showMoviesAsync } from './actions';
import logoImg from '../../assets/images/logo.jpg';
import config from '../../config';
import { selectInfo, selectHome } from './selectors';
class Home extends React.Component {
static propTypes = {
dispatch: PropTypes.func.isRequired,
home: PropTypes.object.isRequired,
homeinfo: PropTypes.string,
history: PropTypes.object.isRequired,
}
static defaultProps = {
homeinfo: undefined,
}
state = {
info: 'Hahoo App!'
}
componentDidMount() {
const { dispatch } = this.props;
if (!this.props.homeinfo) dispatch(showHello('About'));
if (!this.props.home.moviesTotal) dispatch(showMoviesAsync());
if (!this.props.home.name || !this.props.home.infoAsync) {
dispatch(showHelloAsync('This is the content of'));
}
}
render() {
const styles = require('./styles.css');
const { home, homeinfo, history } = this.props;
return (
<div className={styles.main}>
<Helmet title={config.app.title} />
<div className={styles.logo}><img src={logoImg} alt="" /></div>
<h1>{this.state.info}</h1>
<h2 className={styles.aboutBox}>
<span onClick={() => history.push('/about')} role="link" tabIndex="0" className={styles.about}>
{homeinfo}
</span>
</h2>
<h2>Loading remote: movies {home.moviesTotal}</h2>
<h3>{home.name} {home.infoAsync}</h3>
</div>
);
}
}
Home.fetchData = ({ store }) => {
const fetch = Promise.all([
store.dispatch(showHelloAsync('This is the content of')),
store.dispatch(showMoviesAsync()),
store.dispatch(showHello('About'))
]);
return fetch;
};
const mapStateToProps = state => ({
home: selectHome(state).toObject(),
homeinfo: selectInfo(state),
});
export default connect(mapStateToProps)(Home);