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-04-23 07:13:29 +01:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl'
|
2020-07-02 02:36:53 +01:00
|
|
|
import {
|
|
|
|
fetchRelatedSuggestions,
|
2020-09-01 17:54:01 +01:00
|
|
|
fetchPopularSuggestions,
|
2020-07-02 02:36:53 +01:00
|
|
|
} from '../../actions/suggestions'
|
2020-04-23 07:13:29 +01:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
2020-07-28 21:11:51 +01:00
|
|
|
import Account from '../account'
|
|
|
|
import AccountPlaceholder from '../placeholder/account_placeholder'
|
2020-04-23 07:13:29 +01:00
|
|
|
import PanelLayout from './panel_layout'
|
2019-08-07 06:02:36 +01:00
|
|
|
|
2020-09-01 17:54:01 +01:00
|
|
|
class UserSuggestionsPanel extends ImmutablePureComponent {
|
2019-08-07 06:02:36 +01:00
|
|
|
|
2020-06-05 20:28:46 +01:00
|
|
|
state = {
|
|
|
|
fetched: !this.props.isLazy,
|
2020-04-23 07:13:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
updateOnProps = [
|
|
|
|
'suggestions',
|
2020-06-05 20:28:46 +01:00
|
|
|
'isLazy',
|
|
|
|
'shouldLoad',
|
2020-04-23 07:13:29 +01:00
|
|
|
]
|
2019-08-07 06:02:36 +01:00
|
|
|
|
2020-06-05 20:28:46 +01:00
|
|
|
static getDerivedStateFromProps(nextProps, prevState) {
|
|
|
|
if (nextProps.shouldLoad && !prevState.fetched) {
|
|
|
|
return { fetched: true }
|
|
|
|
}
|
|
|
|
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps, prevState) {
|
|
|
|
if (!prevState.fetched && this.state.fetched) {
|
2021-01-09 02:46:03 +00:00
|
|
|
// this.handleFetch()
|
2020-06-05 20:28:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-10 04:26:58 +01:00
|
|
|
componentDidMount() {
|
2020-06-05 20:28:46 +01:00
|
|
|
if (!this.props.isLazy) {
|
2021-01-09 02:46:03 +00:00
|
|
|
// this.handleFetch()
|
2020-09-01 17:54:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleFetch = () => {
|
|
|
|
if (this.props.suggestionType === 'verified') {
|
|
|
|
this.props.fetchPopularSuggestions()
|
|
|
|
} else {
|
2020-07-02 02:36:53 +01:00
|
|
|
this.props.fetchRelatedSuggestions()
|
2020-06-05 20:28:46 +01:00
|
|
|
}
|
2019-08-07 06:02:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2020-07-02 02:36:53 +01:00
|
|
|
const {
|
|
|
|
intl,
|
2020-07-28 21:11:51 +01:00
|
|
|
isLoading,
|
2020-07-02 02:36:53 +01:00
|
|
|
suggestions,
|
2020-09-01 17:54:01 +01:00
|
|
|
suggestionType,
|
2020-07-02 02:36:53 +01:00
|
|
|
} = this.props
|
2020-04-23 07:13:29 +01:00
|
|
|
|
2021-01-09 02:46:03 +00:00
|
|
|
return null
|
2020-04-28 06:33:58 +01:00
|
|
|
if (suggestions.isEmpty()) return null
|
2019-08-07 06:02:36 +01:00
|
|
|
|
2020-07-28 21:11:51 +01:00
|
|
|
const Child = isLoading ? AccountPlaceholder : Account
|
|
|
|
const arr = isLoading ? Array.apply(null, { length: 6 }) : suggestions
|
|
|
|
|
2020-09-01 17:54:01 +01:00
|
|
|
const title = suggestionType === 'verified' ? intl.formatMessage(messages.verifiedTitle) : intl.formatMessage(messages.relatedTitle)
|
|
|
|
|
2019-08-07 06:02:36 +01:00
|
|
|
return (
|
2020-02-21 00:57:29 +00:00
|
|
|
<PanelLayout
|
2020-04-28 06:33:58 +01:00
|
|
|
noPadding
|
2020-09-01 17:54:01 +01:00
|
|
|
title={title}
|
2020-07-07 21:55:59 +01:00
|
|
|
footerButtonTitle={intl.formatMessage(messages.show_more)}
|
2020-09-01 17:54:01 +01:00
|
|
|
footerButtonTo='/suggestions'
|
2020-02-21 00:57:29 +00:00
|
|
|
>
|
2020-08-18 21:49:11 +01:00
|
|
|
<div className={_s.d}>
|
2020-04-23 07:13:29 +01:00
|
|
|
{
|
2020-07-28 21:11:51 +01:00
|
|
|
arr.map((accountId) => (
|
|
|
|
<Child
|
2020-04-28 06:33:58 +01:00
|
|
|
compact
|
2020-04-23 07:13:29 +01:00
|
|
|
key={accountId}
|
|
|
|
id={accountId}
|
2020-07-29 21:40:47 +01:00
|
|
|
isSmall={isLoading ? true : undefined}
|
2020-04-23 07:13:29 +01:00
|
|
|
/>
|
|
|
|
))
|
|
|
|
}
|
2019-08-07 06:02:36 +01:00
|
|
|
</div>
|
|
|
|
</PanelLayout>
|
2020-04-23 07:13:29 +01:00
|
|
|
)
|
|
|
|
}
|
2020-08-19 01:22:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
dismissSuggestion: { id: 'suggestions.dismiss', defaultMessage: 'Dismiss suggestion' },
|
2020-09-01 17:54:01 +01:00
|
|
|
relatedTitle: { id: 'who_to_follow.title', defaultMessage: 'Who to Follow' },
|
|
|
|
verifiedTitle: { id: 'who_to_follow.verified_title', defaultMessage: 'Verified Accounts to Follow' },
|
2020-08-19 01:22:15 +01:00
|
|
|
show_more: { id: 'who_to_follow.more', defaultMessage: 'Show more' },
|
|
|
|
})
|
|
|
|
|
2020-09-01 17:54:01 +01:00
|
|
|
const mapStateToProps = (state, { suggestionType = 'related' }) => ({
|
|
|
|
suggestions: state.getIn(['suggestions', suggestionType, 'items']),
|
|
|
|
isLoading: state.getIn(['suggestions', suggestionType, 'isLoading']),
|
2020-08-19 01:22:15 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
fetchRelatedSuggestions: () => dispatch(fetchRelatedSuggestions()),
|
2020-09-01 17:54:01 +01:00
|
|
|
fetchPopularSuggestions: () => dispatch(fetchPopularSuggestions()),
|
2020-08-19 01:22:15 +01:00
|
|
|
})
|
|
|
|
|
2020-09-01 17:54:01 +01:00
|
|
|
UserSuggestionsPanel.propTypes = {
|
|
|
|
suggestionType: PropTypes.oneOf([
|
|
|
|
'related',
|
|
|
|
'verified'
|
|
|
|
]),
|
2020-08-19 01:22:15 +01:00
|
|
|
fetchRelatedSuggestions: PropTypes.func.isRequired,
|
2020-09-01 17:54:01 +01:00
|
|
|
fetchPopularSuggestions: PropTypes.func.isRequired,
|
2020-08-19 01:22:15 +01:00
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
suggestions: ImmutablePropTypes.list.isRequired,
|
|
|
|
isLoading: PropTypes.bool.isRequired,
|
|
|
|
isLazy: PropTypes.bool,
|
|
|
|
}
|
|
|
|
|
2020-09-01 17:54:01 +01:00
|
|
|
UserSuggestionsPanel.defaultProps = {
|
|
|
|
suggestionType: 'related',
|
|
|
|
}
|
|
|
|
|
|
|
|
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(UserSuggestionsPanel))
|