2020-06-05 15:28:46 -04:00
|
|
|
import throttle from 'lodash.throttle'
|
2020-03-24 00:39:12 -04:00
|
|
|
import { openModal } from '../actions/modal'
|
2020-04-16 02:00:43 -04:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl'
|
2020-05-03 01:22:49 -04:00
|
|
|
import { MODAL_HOME_TIMELINE_SETTINGS } from '../constants'
|
2020-05-14 02:03:22 -04:00
|
|
|
import { me } from '../initial_state'
|
2020-04-11 18:29:19 -04:00
|
|
|
import PageTitle from '../features/ui/util/page_title'
|
2020-04-03 19:18:26 -04:00
|
|
|
import GroupsPanel from '../components/panel/groups_panel'
|
|
|
|
import ListsPanel from '../components/panel/lists_panel'
|
2020-02-08 01:12:01 -05:00
|
|
|
import LinkFooter from '../components/link_footer'
|
|
|
|
import WhoToFollowPanel from '../components/panel/who_to_follow_panel'
|
2020-07-01 21:33:10 -04:00
|
|
|
import ShopPanel from '../components/panel/shop_panel'
|
2020-02-08 01:12:01 -05:00
|
|
|
import ProgressPanel from '../components/panel/progress_panel'
|
2020-05-14 02:03:22 -04:00
|
|
|
import ProPanel from '../components/panel/pro_panel'
|
2020-02-19 18:57:07 -05:00
|
|
|
import UserPanel from '../components/panel/user_panel'
|
|
|
|
import TrendsPanel from '../components/panel/trends_panel'
|
2020-02-24 16:56:07 -05:00
|
|
|
import DefaultLayout from '../layouts/default_layout'
|
2020-02-08 01:12:01 -05:00
|
|
|
import TimelineComposeBlock from '../components/timeline_compose_block'
|
2020-02-19 18:57:07 -05:00
|
|
|
import Divider from '../components/divider'
|
2020-05-07 00:03:34 -04:00
|
|
|
import PullToRefresher from '../components/pull_to_refresher'
|
2019-07-08 23:49:44 -04:00
|
|
|
|
2020-04-16 02:00:43 -04:00
|
|
|
const messages = defineMessages({
|
|
|
|
home: { id: 'home', defaultMessage: 'Home' },
|
|
|
|
})
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => ({
|
|
|
|
totalQueuedItemsCount: state.getIn(['timelines', 'home', 'totalQueuedItemsCount']),
|
2020-05-14 02:03:22 -04:00
|
|
|
isPro: state.getIn(['accounts', me, 'is_pro']),
|
2020-04-16 02:00:43 -04:00
|
|
|
})
|
|
|
|
|
2020-03-24 00:39:12 -04:00
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
onOpenHomePageSettingsModal() {
|
2020-05-03 01:22:49 -04:00
|
|
|
dispatch(openModal(MODAL_HOME_TIMELINE_SETTINGS))
|
2020-03-24 00:39:12 -04:00
|
|
|
},
|
|
|
|
})
|
2020-02-19 18:57:07 -05:00
|
|
|
|
2020-03-24 00:39:12 -04:00
|
|
|
export default
|
2020-04-16 02:00:43 -04:00
|
|
|
@injectIntl
|
|
|
|
@connect(mapStateToProps, mapDispatchToProps)
|
2020-03-24 00:39:12 -04:00
|
|
|
class HomePage extends PureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
2020-04-16 02:00:43 -04:00
|
|
|
children: PropTypes.node.isRequired,
|
2020-05-03 01:22:49 -04:00
|
|
|
intl: PropTypes.object.isRequired,
|
2020-03-24 00:39:12 -04:00
|
|
|
onOpenHomePageSettingsModal: PropTypes.func.isRequired,
|
2020-05-03 01:22:49 -04:00
|
|
|
totalQueuedItemsCount: PropTypes.number.isRequired,
|
2020-05-14 02:03:22 -04:00
|
|
|
isPro: PropTypes.bool,
|
2020-03-12 12:09:15 -04:00
|
|
|
}
|
|
|
|
|
2020-06-05 15:28:46 -04:00
|
|
|
state = {
|
|
|
|
lazyLoaded: false,
|
|
|
|
}
|
2020-04-28 01:33:58 -04:00
|
|
|
|
2020-06-05 15:28:46 -04:00
|
|
|
componentDidMount() {
|
|
|
|
this.window = window
|
|
|
|
this.documentElement = document.scrollingElement || document.documentElement
|
2020-04-28 01:33:58 -04:00
|
|
|
|
2020-06-05 15:28:46 -04:00
|
|
|
this.window.addEventListener('scroll', this.handleScroll)
|
|
|
|
}
|
2020-04-28 01:33:58 -04:00
|
|
|
|
2020-06-05 15:28:46 -04:00
|
|
|
componentWillUnmount() {
|
|
|
|
this.detachScrollListener()
|
|
|
|
}
|
|
|
|
|
|
|
|
detachScrollListener = () => {
|
|
|
|
this.window.removeEventListener('scroll', this.handleScroll)
|
|
|
|
}
|
2020-04-28 01:33:58 -04:00
|
|
|
|
2020-06-05 15:28:46 -04:00
|
|
|
handleScroll = throttle(() => {
|
|
|
|
if (this.window) {
|
|
|
|
const { scrollTop } = this.documentElement
|
|
|
|
|
|
|
|
if (scrollTop > 25 && !this.state.lazyLoaded) {
|
|
|
|
this.setState({ lazyLoaded: true })
|
|
|
|
this.detachScrollListener()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 150, {
|
|
|
|
trailing: true,
|
|
|
|
})
|
2020-04-28 01:33:58 -04:00
|
|
|
|
2020-02-08 01:12:01 -05:00
|
|
|
render() {
|
2020-04-16 02:00:43 -04:00
|
|
|
const {
|
|
|
|
intl,
|
|
|
|
children,
|
|
|
|
totalQueuedItemsCount,
|
|
|
|
onOpenHomePageSettingsModal,
|
2020-05-14 02:03:22 -04:00
|
|
|
isPro,
|
2020-04-16 02:00:43 -04:00
|
|
|
} = this.props
|
2020-06-05 15:28:46 -04:00
|
|
|
const { lazyLoaded } = this.state
|
2019-07-08 23:49:44 -04:00
|
|
|
|
|
|
|
return (
|
2020-02-17 12:50:29 -05:00
|
|
|
<DefaultLayout
|
2020-07-15 23:05:08 -05:00
|
|
|
page='home'
|
2020-04-16 02:00:43 -04:00
|
|
|
title={intl.formatMessage(messages.home)}
|
2020-02-19 18:57:07 -05:00
|
|
|
actions={[
|
2020-05-06 19:40:54 -04:00
|
|
|
{
|
|
|
|
icon: 'ellipsis',
|
|
|
|
onClick: onOpenHomePageSettingsModal,
|
|
|
|
},
|
2020-02-19 18:57:07 -05:00
|
|
|
]}
|
2020-07-15 23:05:08 -05:00
|
|
|
layout={[
|
|
|
|
<UserPanel key='home-page-user-panel' />,
|
|
|
|
<ProgressPanel key='home-page-progress-panel' />,
|
|
|
|
<ProPanel isPro={isPro} key='home-page-pro-panel' />,
|
|
|
|
<TrendsPanel key='home-page-trends-panel' />,
|
|
|
|
<ShopPanel isLazy shouldLoad={lazyLoaded} key='home-page-shop-panel' />,
|
|
|
|
<ListsPanel isLazy shouldLoad={lazyLoaded} key='home-page-lists-panel' />,
|
|
|
|
<WhoToFollowPanel isLazy shouldLoad={lazyLoaded} key='home-page-wtf-panel' />,
|
|
|
|
<GroupsPanel isLazy shouldLoad={lazyLoaded} key='home-page-groups-panel' />,
|
|
|
|
<LinkFooter key='home-page-link-footer' />,
|
|
|
|
]}
|
2019-08-07 01:02:36 -04:00
|
|
|
>
|
2020-05-03 01:22:49 -04:00
|
|
|
|
2020-04-16 02:00:43 -04:00
|
|
|
<PageTitle
|
|
|
|
path={intl.formatMessage(messages.home)}
|
|
|
|
badge={totalQueuedItemsCount}
|
|
|
|
/>
|
2020-05-03 01:22:49 -04:00
|
|
|
|
2020-05-07 00:03:34 -04:00
|
|
|
<PullToRefresher />
|
|
|
|
|
2020-02-28 10:20:47 -05:00
|
|
|
<TimelineComposeBlock autoFocus={false} />
|
2020-05-03 01:22:49 -04:00
|
|
|
|
2020-02-19 18:57:07 -05:00
|
|
|
<Divider />
|
2020-05-03 01:22:49 -04:00
|
|
|
|
2020-02-08 01:12:01 -05:00
|
|
|
{children}
|
2020-05-03 01:22:49 -04:00
|
|
|
|
2020-02-17 12:50:29 -05:00
|
|
|
</DefaultLayout>
|
2019-07-08 23:49:44 -04:00
|
|
|
)
|
|
|
|
}
|
2019-08-07 01:02:36 -04:00
|
|
|
}
|