diff --git a/app/controllers/api/v1/gab_trends_controller.rb b/app/controllers/api/v1/gab_trends_controller.rb index 98ad103f..2a7caf78 100644 --- a/app/controllers/api/v1/gab_trends_controller.rb +++ b/app/controllers/api/v1/gab_trends_controller.rb @@ -22,6 +22,22 @@ class Api::V1::GabTrendsController < Api::BaseController end end + render json: body + elsif type == 'partner' + body = Redis.current.get("gabtrends:partner") + + if body.nil? + uri = URI("https://trends.gab.com/partner") + uri.query = URI.encode_www_form({}) + + res = Net::HTTP.get_response(uri) + if res.is_a?(Net::HTTPSuccess) + body = res.body + Redis.current.set("gabtrends:partner", res.body) + Redis.current.expire("gabtrends:partner", 1.minute.seconds) + end + end + render json: body else raise GabSocial::NotPermittedError diff --git a/app/javascript/gabsocial/actions/gab_trends.js b/app/javascript/gabsocial/actions/gab_trends.js index 8cacf481..084ba722 100644 --- a/app/javascript/gabsocial/actions/gab_trends.js +++ b/app/javascript/gabsocial/actions/gab_trends.js @@ -1,5 +1,4 @@ -import api from '../api'; -import { me } from '../initial_state' +import api from '../api' export const GAB_TRENDS_RESULTS_FETCH_REQUEST = 'GAB_TRENDS_RESULTS_FETCH_REQUEST' export const GAB_TRENDS_RESULTS_FETCH_SUCCESS = 'GAB_TRENDS_RESULTS_FETCH_SUCCESS' @@ -9,8 +8,8 @@ export const fetchGabTrends = (feedType) => { return function (dispatch, getState) { dispatch(fetchGabTrendsRequest(feedType)) - api(getState).get(`/api/v1/gab_trends?type=${feedType}`).then(response => { - dispatch(fetchGabTrendsSuccess(response.data.items, feedType)) + api(getState).get(`/api/v1/gab_trends?type=${feedType}`).then((response) => { + dispatch(fetchGabTrendsSuccess(response.data, feedType)) }).catch(function (error) { dispatch(fetchGabTrendsFail(error, feedType)) }) diff --git a/app/javascript/gabsocial/components/footer_bar.js b/app/javascript/gabsocial/components/footer_bar.js index 30812c2b..668487b0 100644 --- a/app/javascript/gabsocial/components/footer_bar.js +++ b/app/javascript/gabsocial/components/footer_bar.js @@ -51,9 +51,10 @@ class FooterBar extends PureComponent { active: currentPathname === '/groups', }, { - href: 'https://trends.gab.com', + to: '/explore', icon: 'trends', title: 'Trends', + active: currentPathname === '/explore', }, ] diff --git a/app/javascript/gabsocial/components/navigation_bar.js b/app/javascript/gabsocial/components/navigation_bar.js index efc32893..b121aac1 100644 --- a/app/javascript/gabsocial/components/navigation_bar.js +++ b/app/javascript/gabsocial/components/navigation_bar.js @@ -107,7 +107,8 @@ class NavigationBar extends ImmutablePureComponent {
- + + diff --git a/app/javascript/gabsocial/components/panel/trends_panel.js b/app/javascript/gabsocial/components/panel/trends_panel.js index 8fcd3fa7..5b0d7ae5 100644 --- a/app/javascript/gabsocial/components/panel/trends_panel.js +++ b/app/javascript/gabsocial/components/panel/trends_panel.js @@ -68,7 +68,11 @@ class TrendsPanel extends ImmutablePureComponent { key={`gab-trend-${i}`} index={i + 1} isLast={i === 7} - trend={trend} + title={trend.get('title')} + description={trend.get('description')} + url={trend.get('url')} + author={trend.getIn(['author', 'name'], '')} + date={trend.get('date_published')} /> )) } diff --git a/app/javascript/gabsocial/components/pill_item.js b/app/javascript/gabsocial/components/pill_item.js index 61bcdbe6..5c9288a0 100644 --- a/app/javascript/gabsocial/components/pill_item.js +++ b/app/javascript/gabsocial/components/pill_item.js @@ -23,7 +23,7 @@ class PillItem extends PureComponent { // If user navigates to different page, ensure tab bar item // with this.props.to that is on location is set to active. if (this.props.location !== prevProps.location) { - const isCurrent = this.props.to === this.props.location.pathname + const isCurrent = this.props.to === this.props.location.pathname && !this.props.location.search if (this.state.isCurrent !== isCurrent) { this.setState({ isCurrent }) @@ -43,7 +43,7 @@ class PillItem extends PureComponent { // Combine state, props, location to make absolutely // sure of active status. - const active = isActive || to === location.pathname || isCurrent + const active = isActive || (to === location.pathname && !location.search) || isCurrent const containerClasses = CX({ default: 1, diff --git a/app/javascript/gabsocial/components/sidebar.js b/app/javascript/gabsocial/components/sidebar.js index 931d77d0..761ade7f 100644 --- a/app/javascript/gabsocial/components/sidebar.js +++ b/app/javascript/gabsocial/components/sidebar.js @@ -139,6 +139,11 @@ class Sidebar extends ImmutablePureComponent { icon: 'list', to: '/lists', }, + { + title: 'Explore', + icon: 'explore', + to: '/explore', + }, { title: 'More', icon: 'more', diff --git a/app/javascript/gabsocial/components/tab_bar.js b/app/javascript/gabsocial/components/tab_bar.js index e5a558d4..24059c25 100644 --- a/app/javascript/gabsocial/components/tab_bar.js +++ b/app/javascript/gabsocial/components/tab_bar.js @@ -18,7 +18,7 @@ export default class TabBar extends PureComponent { return ( { diff --git a/app/javascript/gabsocial/components/tab_bar_item.js b/app/javascript/gabsocial/components/tab_bar_item.js index 15a92c12..a9eaa64e 100644 --- a/app/javascript/gabsocial/components/tab_bar_item.js +++ b/app/javascript/gabsocial/components/tab_bar_item.js @@ -31,7 +31,7 @@ class TabBarItem extends PureComponent { // If user navigates to different page, ensure tab bar item // with this.props.to that is on location is set to active. if (this.props.location !== prevProps.location) { - const isCurrent = this.props.to === this.props.location.pathname + const isCurrent = this.props.to === this.props.location.pathname && !this.props.location.search if (this.state.isCurrent !== isCurrent) { this.setState({ isCurrent }) @@ -52,7 +52,7 @@ class TabBarItem extends PureComponent { // Combine state, props, location to make absolutely // sure of active status. - const active = isActive || to === location.pathname || isCurrent + const active = isActive || (to === location.pathname && !location.search) || isCurrent const containerClasses = CX({ default: 1, diff --git a/app/javascript/gabsocial/components/trends_item.js b/app/javascript/gabsocial/components/trends_item.js index 1d1eb6ec..6446247f 100644 --- a/app/javascript/gabsocial/components/trends_item.js +++ b/app/javascript/gabsocial/components/trends_item.js @@ -1,6 +1,4 @@ import { Fragment } from 'react' -import ImmutablePureComponent from 'react-immutable-pure-component' -import ImmutablePropTypes from 'react-immutable-proptypes' import { urlRegex } from '../features/ui/util/url_regex' import { CX, @@ -8,23 +6,28 @@ import { } from '../constants' import Button from './button' import DotTextSeperator from './dot_text_seperator' -import Image from './image' import RelativeTimestamp from './relative_timestamp' import Text from './text' -export default class TrendingItem extends ImmutablePureComponent { +export default class TrendingItem extends PureComponent { static propTypes = { index: PropTypes.number, - trend: ImmutablePropTypes.map.isRequired, isLast: PropTypes.bool, isHidden: PropTypes.bool, + title: PropTypes.string, + description: PropTypes.string, + author: PropTypes.string, + url: PropTypes.string, + date: PropTypes.string, } static defaultProps = { title: '', description: '', author: '', + url: '', + date: '', } state = { @@ -42,25 +45,29 @@ export default class TrendingItem extends ImmutablePureComponent { render() { const { index, - trend, isLast, isHidden, + title, + description, + author, + url, + date, } = this.props const { hovering } = this.state - if (!trend) return null + if (!title || !url) return null - const title = `${trend.get('title')}`.trim() - const description = trend.get('description') || '' + const correctedTitle = `${title}`.trim() + let correctedDescription = description || '' - const correctedAuthor = trend.getIn(['author', 'name'], '').replace('www.', '') - const correctedDescription = description.length >= 120 ? `${description.substring(0, 120).trim()}...` : description + const correctedAuthor = `${author}`.replace('www.', '') + correctedDescription = correctedDescription.length >= 120 ? `${correctedDescription.substring(0, 120).trim()}...` : correctedDescription const descriptionHasLink = correctedDescription.match(urlRegex) if (isHidden) { return ( - {title} + {correctedTitle} {!descriptionHasLink && correctedDescription} {correctedAuthor} @@ -86,30 +93,18 @@ export default class TrendingItem extends ImmutablePureComponent { return (