2020-08-17 21:07:16 +01:00
|
|
|
import React from 'react'
|
2020-08-17 21:59:29 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2020-08-17 21:39:25 +01:00
|
|
|
import { connect } from 'react-redux'
|
2020-11-07 05:34:23 +00:00
|
|
|
import throttle from 'lodash.throttle'
|
|
|
|
import { fetchPopularLinks } from '../actions/links'
|
2020-11-15 18:48:32 +00:00
|
|
|
import {
|
|
|
|
BREAKPOINT_EXTRA_SMALL,
|
|
|
|
LAZY_LOAD_SCROLL_OFFSET,
|
|
|
|
} from '../constants'
|
2020-08-06 06:12:03 +01:00
|
|
|
import Button from '../components/button'
|
|
|
|
import Text from '../components/text'
|
|
|
|
import TrendsItem from '../components/trends_item'
|
2020-11-07 05:34:23 +00:00
|
|
|
import PreviewCardItem from '../components/preview_card_item'
|
|
|
|
import WrappedBundle from './ui/util/wrapped_bundle'
|
|
|
|
import {
|
|
|
|
GabNewsPanel,
|
|
|
|
LatestFromGabPanel,
|
|
|
|
PopularLinksPanel,
|
|
|
|
TrendsBreakingPanel,
|
|
|
|
TrendsFeedsPanel,
|
|
|
|
TrendsHeadlinesPanel,
|
|
|
|
TrendsRSSPanel,
|
|
|
|
} from './ui/util/async_components'
|
2020-08-06 06:12:03 +01:00
|
|
|
|
2020-08-17 21:07:16 +01:00
|
|
|
class News extends React.PureComponent {
|
2020-08-06 06:12:03 +01:00
|
|
|
|
|
|
|
state = {
|
2020-11-07 05:34:23 +00:00
|
|
|
lazyLoaded: false,
|
2020-08-06 06:12:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2020-11-07 05:34:23 +00:00
|
|
|
this.window = window
|
|
|
|
this.documentElement = document.scrollingElement || document.documentElement
|
2020-08-06 06:12:03 +01:00
|
|
|
|
2020-11-07 05:34:23 +00:00
|
|
|
this.window.addEventListener('scroll', this.handleScroll)
|
2020-12-09 04:57:51 +00:00
|
|
|
|
|
|
|
window.addEventListener('keyup', this.handleKeyUp, false)
|
2020-08-06 06:12:03 +01:00
|
|
|
}
|
|
|
|
|
2020-11-07 05:34:23 +00:00
|
|
|
componentWillUnmount() {
|
|
|
|
this.detachScrollListener()
|
2020-12-09 04:57:51 +00:00
|
|
|
window.removeEventListener('keyup', this.handleKeyUp)
|
2020-11-07 05:34:23 +00:00
|
|
|
}
|
2020-08-06 06:12:03 +01:00
|
|
|
|
2020-11-07 05:34:23 +00:00
|
|
|
detachScrollListener = () => {
|
|
|
|
this.window.removeEventListener('scroll', this.handleScroll)
|
|
|
|
}
|
2020-08-19 01:22:15 +01:00
|
|
|
|
2020-11-07 05:34:23 +00:00
|
|
|
handleScroll = throttle(() => {
|
|
|
|
if (this.window) {
|
|
|
|
const { scrollTop } = this.documentElement
|
|
|
|
|
2020-11-15 18:48:32 +00:00
|
|
|
if (scrollTop > LAZY_LOAD_SCROLL_OFFSET && !this.state.lazyLoaded) {
|
2020-11-07 05:34:23 +00:00
|
|
|
this.setState({ lazyLoaded: true })
|
|
|
|
this.detachScrollListener()
|
2020-08-06 06:12:03 +01:00
|
|
|
}
|
|
|
|
}
|
2020-11-15 18:48:32 +00:00
|
|
|
}, 150, { trailing: true })
|
2020-08-06 06:12:03 +01:00
|
|
|
|
2020-11-07 05:34:23 +00:00
|
|
|
render() {
|
2021-01-08 05:15:53 +00:00
|
|
|
const { children, isSmall, width } = this.props
|
|
|
|
const { lazyLoaded } = this.state
|
2020-11-07 05:34:23 +00:00
|
|
|
|
2020-12-09 04:57:51 +00:00
|
|
|
const isXS = width <= BREAKPOINT_EXTRA_SMALL
|
2020-08-06 06:12:03 +01:00
|
|
|
|
2020-12-09 04:57:51 +00:00
|
|
|
if (isXS || isSmall) {
|
|
|
|
return (
|
|
|
|
<div className={[_s.d, _s.w100PC].join(' ')}>
|
|
|
|
<div className={[_s.d, _s.pt15].join(' ')}>
|
|
|
|
<div className={[_s.d, _s.w100PC].join(' ')}>
|
2020-11-09 19:47:46 +00:00
|
|
|
<WrappedBundle component={TrendsHeadlinesPanel} />
|
|
|
|
<WrappedBundle component={TrendsBreakingPanel} componentParams={{ hideReadMore: 1 }} />
|
|
|
|
<WrappedBundle component={PopularLinksPanel} componentParams={{ isLazy: true, shouldLoad: lazyLoaded }} />
|
|
|
|
<WrappedBundle component={LatestFromGabPanel} componentParams={{ isLazy: true, shouldLoad: lazyLoaded }} />
|
|
|
|
<WrappedBundle component={GabNewsPanel} componentParams={{ isLazy: true, shouldLoad: lazyLoaded }} />
|
|
|
|
<WrappedBundle component={TrendsFeedsPanel} />
|
|
|
|
</div>
|
2020-12-09 04:57:51 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
2020-08-19 01:22:15 +01:00
|
|
|
|
2020-12-09 04:57:51 +00:00
|
|
|
return (
|
|
|
|
<div className={[_s.d, _s.w100PC].join(' ')}>
|
|
|
|
<div className={[_s.d, _s.flexRow, _s.w100PC, _s.overflowHidden].join(' ')}>
|
|
|
|
<div className={[_s.d, _s.pr15, _s.w50PC].join(' ')}>
|
|
|
|
<WrappedBundle component={TrendsHeadlinesPanel} />
|
|
|
|
<WrappedBundle component={TrendsBreakingPanel} componentParams={{ hideReadMore: 1 }} />
|
|
|
|
<WrappedBundle component={LatestFromGabPanel} componentParams={{ isLazy: true, shouldLoad: lazyLoaded }} />
|
|
|
|
</div>
|
2020-12-30 17:18:15 +00:00
|
|
|
<div className={[_s.d, _s.w50PC].join(' ')}>
|
2020-12-09 04:57:51 +00:00
|
|
|
<WrappedBundle component={PopularLinksPanel} />
|
|
|
|
<WrappedBundle component={TrendsFeedsPanel} />
|
|
|
|
<WrappedBundle component={GabNewsPanel} componentParams={{ isLazy: true, shouldLoad: lazyLoaded }} />
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-08-06 06:12:03 +01:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-08-19 01:22:15 +01:00
|
|
|
}
|
|
|
|
|
2021-01-08 05:15:53 +00:00
|
|
|
const mapStateToProps = (state) => ({
|
|
|
|
width: state.getIn(['settings', 'window_dimensions', 'width']),
|
|
|
|
})
|
|
|
|
|
2020-12-09 04:57:51 +00:00
|
|
|
News.propTypes = {
|
|
|
|
isSmall: PropTypes.bool,
|
|
|
|
}
|
|
|
|
|
2021-01-08 05:15:53 +00:00
|
|
|
export default connect(mapStateToProps)(News)
|