import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import throttle from 'lodash.throttle'
import { openModal } from '../actions/modal'
import { defineMessages, injectIntl } from 'react-intl'
import { MODAL_HOME_TIMELINE_SETTINGS } from '../constants'
import { me } from '../initial_state'
import PageTitle from '../features/ui/util/page_title'
import DefaultLayout from '../layouts/default_layout'
import TimelineComposeBlock from '../components/timeline_compose_block'
import WrappedBundle from '../features/ui/util/wrapped_bundle'
import {
UserPanel,
GroupsPanel,
LinkFooter,
ListsPanel,
TrendsPanel,
UserSuggestionsPanel,
ProPanel,
ShopPanel,
ProgressPanel,
} from '../features/ui/util/async_components'
class HomePage extends React.PureComponent {
state = {
lazyLoaded: false,
}
componentDidMount() {
this.window = window
this.documentElement = document.scrollingElement || document.documentElement
this.window.addEventListener('scroll', this.handleScroll)
}
componentWillUnmount() {
this.detachScrollListener()
}
detachScrollListener = () => {
this.window.removeEventListener('scroll', this.handleScroll)
}
handleScroll = throttle(() => {
if (this.window) {
const { scrollTop } = this.documentElement
if (scrollTop > 25 && !this.state.lazyLoaded) {
this.setState({ lazyLoaded: true })
this.detachScrollListener()
}
}
}, 150, {
trailing: true,
})
onOpenHomePageSettingsModal = () => {
this.props.dispatch(openModal(MODAL_HOME_TIMELINE_SETTINGS))
}
render() {
const {
children,
intl,
isPro,
totalQueuedItemsCount,
} = this.props
const { lazyLoaded } = this.state
const title = intl.formatMessage(messages.home)
return (
,
TrendsPanel,
,
,
,
,
LinkFooter,
]}
>
{children}
)
}
}
const messages = defineMessages({
home: { id: 'home', defaultMessage: 'Home' },
})
const mapStateToProps = (state) => ({
totalQueuedItemsCount: state.getIn(['timelines', 'home', 'totalQueuedItemsCount']),
isPro: state.getIn(['accounts', me, 'is_pro']),
})
HomePage.propTypes = {
children: PropTypes.node.isRequired,
dispatch: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
isPro: PropTypes.bool,
totalQueuedItemsCount: PropTypes.number.isRequired,
}
export default injectIntl(connect(mapStateToProps)(HomePage))