diff --git a/app/javascript/gabsocial/actions/news.js b/app/javascript/gabsocial/actions/news.js
index 84736ffc..db108c38 100644
--- a/app/javascript/gabsocial/actions/news.js
+++ b/app/javascript/gabsocial/actions/news.js
@@ -1,6 +1,7 @@
import api from '../api'
import axios from 'axios'
import { importFetchedStatuses } from './importer'
+import { TRENDS_RSS_SOURCES } from '../constants'
export const GAB_TRENDS_FETCH_REQUEST = 'GAB_TRENDS_FETCH_REQUEST'
export const GAB_TRENDS_FETCH_SUCCESS = 'GAB_TRENDS_FETCH_SUCCESS'
@@ -54,36 +55,40 @@ const fetchGabTrendsFail = (error) => ({
/**
*
*/
-export const expandGabTrendsFeed = (feedId, page = 0) => (dispatch, getState) => {
- dispatch(expandGabTrendsFeedRequest(feedId, page))
+export const expandGabTrendsFeed = (feedId) => (dispatch, getState) => {
+ if (!feedId) return
+ const exists = !!TRENDS_RSS_SOURCES.find((block) => block.id === feedId)
+ if (!exists) return
- // const url = `http://trends.gab.com/feed/${feedId}?fmt=json`
- api(getState).get(`/api/v1/gab_trends?type=rss`).then((response) => {
+ const page = getState().getIn(['news', 'trends_feeds', `${feedId}`, 'curPage'], 0) + 1
+
+ dispatch(expandGabTrendsFeedRequest(feedId))
+
+ // const url = `http://trends.gab.com/feed/${feedId}?fmt=json&p=${page}`
+ api(getState).get(`/api/v1/gab_trends?type=rss&page=${page}&feedId=${feedId}`).then((response) => {
// axios.get(url).then((response) => {
- dispatch(expandGabTrendsFeedSuccess(response.data, feedId, page))
+ dispatch(expandGabTrendsFeedSuccess(response.data.rssFeedItems, feedId, response.data.pagination.p))
}).catch((error) => {
- dispatch(expandGabTrendsFeedFail(error, feedId, page))
+ dispatch(expandGabTrendsFeedFail(error, feedId))
})
}
-const expandGabTrendsFeedRequest = (feedId, page) => ({
+const expandGabTrendsFeedRequest = (feedId) => ({
type: GAB_TREND_FEED_EXPAND_REQUEST,
feedId,
- page,
})
-const expandGabTrendsFeedSuccess = (items, feedId, page) => ({
+const expandGabTrendsFeedSuccess = (items, feedId, curPage) => ({
type: GAB_TREND_FEED_EXPAND_SUCCESS,
items,
feedId,
- page,
+ curPage,
})
-const expandGabTrendsFeedFail = (error, feedId, page) => ({
+const expandGabTrendsFeedFail = (error, feedId) => ({
type: GAB_TREND_FEED_EXPAND_FAIL,
error,
feedId,
- page,
})
/**
diff --git a/app/javascript/gabsocial/components/panel/trends_headlines_panel.js b/app/javascript/gabsocial/components/panel/trends_headlines_panel.js
index ed1c92e4..4c589315 100644
--- a/app/javascript/gabsocial/components/panel/trends_headlines_panel.js
+++ b/app/javascript/gabsocial/components/panel/trends_headlines_panel.js
@@ -21,11 +21,11 @@ class TrendsHeadlinesPanel extends ImmutablePureComponent {
} = this.props
const count = !!items ? items.count() : 0
- const trendsLeadlineTitle = trendsLeadline.get('title')
- const trendsLeadlineImage = trendsLeadline.get('image')
- const trendsLeadlineUrl = trendsLeadline.get('trends_url')
+ const trendsLeadlineTitle = trendsLeadline ? trendsLeadline.get('title') : null
+ const trendsLeadlineImage = trendsLeadline ? trendsLeadline.get('image') : null
+ const trendsLeadlineUrl = trendsLeadline ? trendsLeadline.get('trends_url') : null
- if ((count === 0 && isFetched) && (!trendsLeadlineTitle || !trendsLeadlineTitle || !trendsLeadlineTitle)) return null
+ if ((count === 0 && isFetched) && (!trendsLeadlineImage || !trendsLeadlineTitle || !trendsLeadlineTitle)) return null
const leadlineButtonClasses = CX({
d: 1,
@@ -64,18 +64,21 @@ class TrendsHeadlinesPanel extends ImmutablePureComponent {
))
}
-
+ {
+ !!trendsLeadlineImage && !!trendsLeadlineTitle && trendsLeadlineUrl &&
+
+ }
)
}
@@ -85,7 +88,7 @@ const mapStateToProps = (state) => ({
isLoading: state.getIn(['news', 'trends_headlines', 'isLoading']),
isFetched: state.getIn(['news', 'trends_headlines', 'isFetched']),
items: state.getIn(['news', 'trends_headlines', 'items']),
- trendsLeadline: state.getIn(['news', 'trends_leadline']),
+ trendsLeadline: state.getIn(['news', 'trends_leadline', 'items']),
})
TrendsHeadlinesPanel.propTypes = {
diff --git a/app/javascript/gabsocial/components/panel/trends_rss_panel.js b/app/javascript/gabsocial/components/panel/trends_rss_panel.js
index f30e82c0..6b107aa0 100644
--- a/app/javascript/gabsocial/components/panel/trends_rss_panel.js
+++ b/app/javascript/gabsocial/components/panel/trends_rss_panel.js
@@ -1,33 +1,143 @@
import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
+import { List as ImmutableList } from 'immutable'
import ImmutablePureComponent from 'react-immutable-pure-component'
import ImmutablePropTypes from 'react-immutable-proptypes'
+import { expandGabTrendsFeed } from '../../actions/news'
+import {
+ CX,
+ BREAKPOINT_EXTRA_SMALL,
+} from '../../constants'
+import { getWindowDimension } from '../../utils/is_mobile'
import PanelLayout from './panel_layout'
+import TrendsCard from '../trends_card'
+import Button from '../button'
+import LoadMore from '../load_more'
+import ScrollableList from '../scrollable_list'
+
+const initialState = getWindowDimension()
class TrendsRSSPanel extends ImmutablePureComponent {
+ state = {
+ viewType: 0,
+ fetched: false,
+ isXS: initialState.width <= BREAKPOINT_EXTRA_SMALL,
+ }
+
+ 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 })
+ }
+
+ this.handleResize()
+ window.addEventListener('keyup', this.handleKeyUp, false)
+ window.addEventListener('resize', this.handleResize, false)
+ }
+
+ handleResize = () => {
+ const { width } = getWindowDimension()
+
+ this.setState({ isXS: width <= BREAKPOINT_EXTRA_SMALL })
+ }
+
+ componentWillUnmount() {
+ window.removeEventListener('keyup', this.handleKeyUp)
+ window.removeEventListener('resize', this.handleResize, false)
+ }
+
+ onItemViewClick = () => {
+ this.setState({ viewType: this.state.viewType === 0 ? 1 : 0 })
+ }
+
+ handleOnExpand = () => {
+ this.props.dispatch(expandGabTrendsFeed(this.props.trendsRSSId))
+ }
+
render() {
const {
- intl,
- onChange,
- settings,
+ trendsRSSId,
+ isLoading,
+ isFetched,
+ items,
+ hideReadMore,
+ feed,
} = this.props
+ const {
+ fetched,
+ viewType,
+ isXS,
+ } = this.state
+
+ 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,
+ })
return (
-