2020-08-17 15:07:16 -05:00
|
|
|
import React from 'react'
|
2020-08-17 15:59:29 -05:00
|
|
|
import PropTypes from 'prop-types'
|
2020-08-17 15:39:25 -05:00
|
|
|
import { connect } from 'react-redux'
|
2020-06-05 15:28:46 -04:00
|
|
|
import throttle from 'lodash.throttle'
|
2020-04-16 02:00:43 -04:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl'
|
2020-11-15 12:48:32 -06:00
|
|
|
import { openModal } from '../actions/modal'
|
|
|
|
import {
|
|
|
|
MODAL_HOME_TIMELINE_SETTINGS,
|
|
|
|
LAZY_LOAD_SCROLL_OFFSET,
|
|
|
|
} 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-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-11-15 12:48:32 -06:00
|
|
|
import TabBar from '../components/tab_bar'
|
2020-08-12 17:52:46 -05:00
|
|
|
import WrappedBundle from '../features/ui/util/wrapped_bundle'
|
|
|
|
import {
|
|
|
|
UserPanel,
|
|
|
|
GroupsPanel,
|
|
|
|
LinkFooter,
|
|
|
|
ListsPanel,
|
2020-11-06 23:39:17 -06:00
|
|
|
TrendsBreakingPanel,
|
2020-09-01 11:54:01 -05:00
|
|
|
UserSuggestionsPanel,
|
2020-08-12 17:52:46 -05:00
|
|
|
ProPanel,
|
|
|
|
ShopPanel,
|
|
|
|
ProgressPanel,
|
|
|
|
} from '../features/ui/util/async_components'
|
2019-07-08 23:49:44 -04:00
|
|
|
|
2020-08-17 15:07:16 -05:00
|
|
|
class HomePage extends React.PureComponent {
|
2020-03-24 00:39:12 -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
|
|
|
|
|
2020-11-15 12:48:32 -06:00
|
|
|
if (scrollTop > LAZY_LOAD_SCROLL_OFFSET && !this.state.lazyLoaded) {
|
2020-06-05 15:28:46 -04:00
|
|
|
this.setState({ lazyLoaded: true })
|
|
|
|
this.detachScrollListener()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 150, {
|
|
|
|
trailing: true,
|
|
|
|
})
|
2020-04-28 01:33:58 -04:00
|
|
|
|
2020-08-14 12:45:59 -05:00
|
|
|
onOpenHomePageSettingsModal = () => {
|
|
|
|
this.props.dispatch(openModal(MODAL_HOME_TIMELINE_SETTINGS))
|
|
|
|
}
|
|
|
|
|
2020-02-08 01:12:01 -05:00
|
|
|
render() {
|
2020-04-16 02:00:43 -04:00
|
|
|
const {
|
|
|
|
children,
|
2020-08-14 12:45:59 -05:00
|
|
|
intl,
|
2020-05-14 02:03:22 -04:00
|
|
|
isPro,
|
2020-08-14 12:45:59 -05:00
|
|
|
totalQueuedItemsCount,
|
2020-12-03 17:13:11 -05:00
|
|
|
unreadChatsCount,
|
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
|
|
|
|
2020-08-14 12:45:59 -05:00
|
|
|
const title = intl.formatMessage(messages.home)
|
|
|
|
|
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-08-14 12:45:59 -05:00
|
|
|
title={title}
|
2020-02-19 18:57:07 -05:00
|
|
|
actions={[
|
2020-12-21 15:35:50 -05:00
|
|
|
{
|
|
|
|
icon: 'tv',
|
|
|
|
href: 'https://tv.gab.com',
|
|
|
|
},
|
2020-12-03 17:13:11 -05:00
|
|
|
{
|
|
|
|
icon: 'chat',
|
|
|
|
to: '/messages',
|
|
|
|
count: unreadChatsCount,
|
|
|
|
},
|
2020-05-06 19:40:54 -04:00
|
|
|
{
|
2020-10-31 18:37:57 -05:00
|
|
|
icon: 'search',
|
|
|
|
to: '/search',
|
2020-05-06 19:40:54 -04:00
|
|
|
},
|
2020-02-19 18:57:07 -05:00
|
|
|
]}
|
2020-07-15 23:05:08 -05:00
|
|
|
layout={[
|
2020-08-12 17:52:46 -05:00
|
|
|
UserPanel,
|
|
|
|
ProgressPanel,
|
|
|
|
<WrappedBundle component={ProPanel} componentParams={{ isPro: isPro }} />,
|
2020-12-09 15:02:43 -05:00
|
|
|
<WrappedBundle component={TrendsBreakingPanel} />,
|
2020-08-12 17:52:46 -05:00
|
|
|
<WrappedBundle component={ShopPanel} componentParams={{ isLazy: true, shouldLoad: lazyLoaded }} />,
|
|
|
|
<WrappedBundle component={ListsPanel} componentParams={{ isLazy: true, shouldLoad: lazyLoaded }} />,
|
2020-09-01 11:54:01 -05:00
|
|
|
<WrappedBundle component={UserSuggestionsPanel} componentParams={{ isLazy: true, shouldLoad: lazyLoaded }} />,
|
2020-08-12 17:52:46 -05:00
|
|
|
<WrappedBundle component={GroupsPanel} componentParams={{ isLazy: true, shouldLoad: lazyLoaded, groupType: 'member' }} />,
|
|
|
|
LinkFooter,
|
2020-07-15 23:05:08 -05:00
|
|
|
]}
|
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
|
2020-08-14 12:45:59 -05:00
|
|
|
path={title}
|
2020-04-16 02:00:43 -04:00
|
|
|
badge={totalQueuedItemsCount}
|
|
|
|
/>
|
2020-05-03 01:22:49 -04:00
|
|
|
|
2020-11-15 12:48:32 -06:00
|
|
|
<TimelineComposeBlock autoFocus={false} />
|
2020-02-08 01:12:01 -05:00
|
|
|
{children}
|
2020-11-15 12:48:32 -06:00
|
|
|
|
2020-02-17 12:50:29 -05:00
|
|
|
</DefaultLayout>
|
2019-07-08 23:49:44 -04:00
|
|
|
)
|
|
|
|
}
|
2020-08-14 12:45:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
home: { id: 'home', defaultMessage: 'Home' },
|
|
|
|
})
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => ({
|
|
|
|
totalQueuedItemsCount: state.getIn(['timelines', 'home', 'totalQueuedItemsCount']),
|
2020-12-03 17:13:11 -05:00
|
|
|
unreadChatsCount: state.getIn(['chats', 'chatsUnreadCount']),
|
2020-08-14 12:45:59 -05:00
|
|
|
isPro: state.getIn(['accounts', me, 'is_pro']),
|
|
|
|
})
|
|
|
|
|
|
|
|
HomePage.propTypes = {
|
|
|
|
children: PropTypes.node.isRequired,
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
isPro: PropTypes.bool,
|
2020-12-03 17:13:11 -05:00
|
|
|
unreadChatsCount: PropTypes.number.isRequired,
|
2020-08-14 12:45:59 -05:00
|
|
|
totalQueuedItemsCount: PropTypes.number.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default injectIntl(connect(mapStateToProps)(HomePage))
|