2020-11-07 05:25:32 +00:00
|
|
|
import React from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import { connect } from 'react-redux'
|
2020-11-09 07:35:59 +00:00
|
|
|
import { List as ImmutableList } from 'immutable'
|
2020-11-07 05:25:32 +00:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
2020-11-09 07:35:59 +00:00
|
|
|
import { expandGabTrendsFeed } from '../../actions/news'
|
|
|
|
import {
|
|
|
|
CX,
|
|
|
|
BREAKPOINT_EXTRA_SMALL,
|
|
|
|
} from '../../constants'
|
2020-11-07 05:25:32 +00:00
|
|
|
import PanelLayout from './panel_layout'
|
2020-11-09 07:35:59 +00:00
|
|
|
import TrendsCard from '../trends_card'
|
|
|
|
import Button from '../button'
|
|
|
|
import LoadMore from '../load_more'
|
|
|
|
import ScrollableList from '../scrollable_list'
|
|
|
|
|
2020-11-07 05:25:32 +00:00
|
|
|
class TrendsRSSPanel extends ImmutablePureComponent {
|
|
|
|
|
2020-11-09 07:35:59 +00:00
|
|
|
state = {
|
|
|
|
viewType: 0,
|
|
|
|
fetched: false,
|
|
|
|
}
|
|
|
|
|
|
|
|
static getDerivedStateFromProps(nextProps, prevState) {
|
|
|
|
if (nextProps.shouldLoad && !prevState.fetched) {
|
|
|
|
return { fetched: true }
|
|
|
|
}
|
|
|
|
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps, prevState) {
|
|
|
|
if ((!prevState.fetched && this.state.fetched && this.props.isLazy) ||
|
|
|
|
((prevProps.trendsRSSId !== this.props.trendsRSSId) && !!prevProps.trendsRSSId)) {
|
|
|
|
this.handleOnExpand()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
if (!this.props.isLazy) {
|
|
|
|
this.handleOnExpand()
|
|
|
|
this.setState({ fetched: true })
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener('keyup', this.handleKeyUp, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
window.removeEventListener('keyup', this.handleKeyUp)
|
|
|
|
}
|
|
|
|
|
|
|
|
onItemViewClick = () => {
|
|
|
|
this.setState({ viewType: this.state.viewType === 0 ? 1 : 0 })
|
|
|
|
}
|
|
|
|
|
|
|
|
handleOnExpand = () => {
|
|
|
|
this.props.dispatch(expandGabTrendsFeed(this.props.trendsRSSId))
|
|
|
|
}
|
|
|
|
|
2020-11-07 05:25:32 +00:00
|
|
|
render() {
|
|
|
|
const {
|
2020-11-09 07:35:59 +00:00
|
|
|
trendsRSSId,
|
|
|
|
isLoading,
|
|
|
|
isFetched,
|
|
|
|
items,
|
|
|
|
hideReadMore,
|
|
|
|
feed,
|
2021-01-08 05:15:53 +00:00
|
|
|
width,
|
2020-11-07 05:25:32 +00:00
|
|
|
} = this.props
|
2020-11-09 07:35:59 +00:00
|
|
|
const {
|
|
|
|
fetched,
|
|
|
|
viewType,
|
|
|
|
} = this.state
|
|
|
|
|
2021-01-08 05:15:53 +00:00
|
|
|
const isXS = width <= BREAKPOINT_EXTRA_SMALL
|
2020-11-09 07:35:59 +00:00
|
|
|
const count = !!items ? items.count() : 0
|
|
|
|
if (count === 0 && fetched) return null
|
|
|
|
const hasMore = count % 10 === 0
|
|
|
|
|
|
|
|
const containerClasses = CX({
|
|
|
|
d: 1,
|
|
|
|
w100PC: 1,
|
|
|
|
flexRow: viewType === 1,
|
|
|
|
flexWrap: viewType === 1,
|
|
|
|
})
|
2020-11-07 05:25:32 +00:00
|
|
|
|
|
|
|
return (
|
2020-11-09 07:35:59 +00:00
|
|
|
<div className={[_s.d, _s.w100PC].join(' ')}>
|
|
|
|
<div className={containerClasses} >
|
|
|
|
<ScrollableList
|
|
|
|
scrollKey={`trends-rss-panel-${trendsRSSId}`}
|
|
|
|
onLoadMore={this.handleOnExpand}
|
|
|
|
hasMore={hasMore}
|
|
|
|
isLoading={isLoading}
|
|
|
|
emptyMessage='No feed items found.'
|
|
|
|
disableInfiniteScroll
|
|
|
|
>
|
|
|
|
{
|
|
|
|
items.map((trend, i) => (
|
|
|
|
<TrendsCard
|
|
|
|
isXS={isXS}
|
|
|
|
trend={trend}
|
|
|
|
viewType={viewType}
|
|
|
|
key={`trend-card-rss-${i}`}
|
|
|
|
/>
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</ScrollableList>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-11-07 05:25:32 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-09 07:35:59 +00:00
|
|
|
const mapStateToProps = (state, { trendsRSSId }) => ({
|
|
|
|
isLoading: state.getIn(['news', 'trends_feeds', `${trendsRSSId}`, 'isLoading'], false),
|
|
|
|
isFetched: state.getIn(['news', 'trends_feeds', `${trendsRSSId}`, 'isFetched'], false),
|
|
|
|
items: state.getIn(['news', 'trends_feeds', `${trendsRSSId}`, 'items'], ImmutableList()),
|
2021-01-08 05:15:53 +00:00
|
|
|
width: state.getIn(['settings', 'window_dimensions', 'width']),
|
2020-11-07 05:25:32 +00:00
|
|
|
})
|
|
|
|
|
2020-11-09 07:35:59 +00:00
|
|
|
TrendsRSSPanel.propTypes = {
|
|
|
|
isLazy: PropTypes.bool,
|
|
|
|
isLoading: PropTypes.bool,
|
|
|
|
isFetched: PropTypes.bool,
|
|
|
|
trendsRSSId: PropTypes.string.isRequired,
|
|
|
|
items: ImmutablePropTypes.list,
|
|
|
|
isPage: PropTypes.bool,
|
2020-11-07 05:25:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps)(TrendsRSSPanel)
|