{"size": 1391, "ext": "js", "max_stars_repo_path": "src/pages/home/index.js", "max_stars_repo_name": "wuduo0701/jianshu", "max_stars_repo_stars_event_min_datetime": "2020-05-26T15:36:34.000Z", "max_stars_repo_stars_event_max_datetime": "2020-10-30T08:29:11.000Z", "max_issues_repo_path": "src/pages/home/index.js", "max_issues_repo_name": "wuduo0701/jianshu", "max_issues_repo_issues_event_min_datetime": "2022-02-19T01:32:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-02-27T03:59:19.000Z", "max_forks_repo_path": "src/pages/home/index.js", "max_forks_repo_name": "wuduo0701/jianshu", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": 2, "max_forks_count": null, "avg_line_length": 25.7592592593, "max_line_length": 82, "alphanum_fraction": 0.6405463695}
import React, { PureComponent } from 'react';
import {connect} from 'react-redux';
import { HomeWrapper, HomeLeft, HomeRight, BackTop} from './style';
import List from './component/List';
import Recommend from './component/Recommend';
import Writer from './component/Writer';
import {actionCreators} from './store/index'

class Home extends PureComponent {
  ScrollTop() {
    window.scroll(0, 0);
  }
  render() {
    return (
      <HomeWrapper>
        <HomeLeft>
          <List />
        </HomeLeft>
        <HomeRight>
          <Recommend />
          <Writer/>
        </HomeRight>
        {this.props.isTop ? <BackTop onClick={this.ScrollTop}>顶部</BackTop> : null}
      </HomeWrapper>
    )
  }
  componentDidMount() {
    this.props.changeHomeData();
    this.bindEvents();
  }
  bindEvents() {
    window.addEventListener('scroll', this.props.changeIsTop);
  }
  componentWillUnmount() {
    window.removeEventListener('scroll', this.props.changeIsTop);
  }
}
const mapState = (state) => ({
  isTop: state.getIn(['home', 'isTop'])
})

const mapDispatch = (dispatch) => ({
  changeHomeData() {
    dispatch(actionCreators.getHomeInfo());
  },
  changeIsTop(e){
    if(document.documentElement.scrollTop > 100) {
      dispatch(actionCreators.TopShow(true))
    }else {
      dispatch(actionCreators.TopShow(false))
    }
  }
})
export default connect(mapState, mapDispatch)(Home);