gab-social/app/javascript/gabsocial/components/panel/user_suggestions_panel.js
mgabdev f4512b4411 Added/removed some functionality to better handle requests/load
- Removed status counting in dashboard for admins
- Added limit to notifications to only 7 days ago
- Removed ability for non-logged in users to view group, group-collection timelines
- Limited account realtime search on compose, list, chat actions
- Removed fetching of user suggestions
- Removed fetching of shortcuts
- Removed featured groups, user suggestions timeline injections
- Removed group featured panel from explore layout for non logged in users
- Removed media gallery panel from profile layout
- Removed lists, suggestions, groups panel from home page
- Removed user suggestions to list page
- Updated pro_timelie in status.rb to find only from 1 hour ago
- Updated home timeline to not include groups and to find only latest from 5 days ago
- Removed search for non logged in users
2021-01-08 21:46:03 -05:00

129 lines
3.5 KiB
JavaScript

import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { defineMessages, injectIntl } from 'react-intl'
import {
fetchRelatedSuggestions,
fetchPopularSuggestions,
} from '../../actions/suggestions'
import ImmutablePureComponent from 'react-immutable-pure-component'
import ImmutablePropTypes from 'react-immutable-proptypes'
import Account from '../account'
import AccountPlaceholder from '../placeholder/account_placeholder'
import PanelLayout from './panel_layout'
class UserSuggestionsPanel extends ImmutablePureComponent {
state = {
fetched: !this.props.isLazy,
}
updateOnProps = [
'suggestions',
'isLazy',
'shouldLoad',
]
static getDerivedStateFromProps(nextProps, prevState) {
if (nextProps.shouldLoad && !prevState.fetched) {
return { fetched: true }
}
return null
}
componentDidUpdate(prevProps, prevState) {
if (!prevState.fetched && this.state.fetched) {
// this.handleFetch()
}
}
componentDidMount() {
if (!this.props.isLazy) {
// this.handleFetch()
}
}
handleFetch = () => {
if (this.props.suggestionType === 'verified') {
this.props.fetchPopularSuggestions()
} else {
this.props.fetchRelatedSuggestions()
}
}
render() {
const {
intl,
isLoading,
suggestions,
suggestionType,
} = this.props
return null
if (suggestions.isEmpty()) return null
const Child = isLoading ? AccountPlaceholder : Account
const arr = isLoading ? Array.apply(null, { length: 6 }) : suggestions
const title = suggestionType === 'verified' ? intl.formatMessage(messages.verifiedTitle) : intl.formatMessage(messages.relatedTitle)
return (
<PanelLayout
noPadding
title={title}
footerButtonTitle={intl.formatMessage(messages.show_more)}
footerButtonTo='/suggestions'
>
<div className={_s.d}>
{
arr.map((accountId) => (
<Child
compact
key={accountId}
id={accountId}
isSmall={isLoading ? true : undefined}
/>
))
}
</div>
</PanelLayout>
)
}
}
const messages = defineMessages({
dismissSuggestion: { id: 'suggestions.dismiss', defaultMessage: 'Dismiss suggestion' },
relatedTitle: { id: 'who_to_follow.title', defaultMessage: 'Who to Follow' },
verifiedTitle: { id: 'who_to_follow.verified_title', defaultMessage: 'Verified Accounts to Follow' },
show_more: { id: 'who_to_follow.more', defaultMessage: 'Show more' },
})
const mapStateToProps = (state, { suggestionType = 'related' }) => ({
suggestions: state.getIn(['suggestions', suggestionType, 'items']),
isLoading: state.getIn(['suggestions', suggestionType, 'isLoading']),
})
const mapDispatchToProps = (dispatch) => ({
fetchRelatedSuggestions: () => dispatch(fetchRelatedSuggestions()),
fetchPopularSuggestions: () => dispatch(fetchPopularSuggestions()),
})
UserSuggestionsPanel.propTypes = {
suggestionType: PropTypes.oneOf([
'related',
'verified'
]),
fetchRelatedSuggestions: PropTypes.func.isRequired,
fetchPopularSuggestions: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
suggestions: ImmutablePropTypes.list.isRequired,
isLoading: PropTypes.bool.isRequired,
isLazy: PropTypes.bool,
}
UserSuggestionsPanel.defaultProps = {
suggestionType: 'related',
}
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(UserSuggestionsPanel))