2020-03-04 22:26:01 +00:00
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component'
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'
|
2020-04-08 02:06:59 +01:00
|
|
|
import debounce from 'lodash.debounce'
|
2020-03-04 22:26:01 +00:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl'
|
|
|
|
import {
|
|
|
|
fetchFollowing,
|
|
|
|
expandFollowing,
|
|
|
|
} from '../actions/accounts'
|
2020-04-11 23:29:19 +01:00
|
|
|
import Account from '../components/account'
|
2020-03-04 22:26:01 +00:00
|
|
|
import ScrollableList from '../components/scrollable_list'
|
|
|
|
import Block from '../components/block'
|
|
|
|
import Heading from '../components/heading'
|
|
|
|
|
|
|
|
const mapStateToProps = (state, { account }) => {
|
|
|
|
const accountId = !!account ? account.get('id') : -1
|
|
|
|
|
|
|
|
return {
|
|
|
|
accountId,
|
|
|
|
accountIds: state.getIn(['user_lists', 'following', accountId, 'items']),
|
|
|
|
hasMore: !!state.getIn(['user_lists', 'following', accountId, 'next']),
|
2020-05-01 06:50:27 +01:00
|
|
|
isLoading: state.getIn(['user_lists', 'following', accountId, 'isLoading'], true),
|
2020-03-04 22:26:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
follows: { id: 'account.follows', defaultMessage: 'Follows' },
|
|
|
|
empty: { id: 'account.follows.empty', defaultMessage: 'This user doesn\'t follow anyone yet.' },
|
|
|
|
})
|
|
|
|
|
|
|
|
export default
|
|
|
|
@connect(mapStateToProps)
|
|
|
|
@injectIntl
|
|
|
|
class Following extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
params: PropTypes.object.isRequired,
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
|
|
|
accountIds: ImmutablePropTypes.list,
|
|
|
|
account: ImmutablePropTypes.map,
|
|
|
|
accountId: PropTypes.string,
|
|
|
|
hasMore: PropTypes.bool,
|
2020-05-01 06:50:27 +01:00
|
|
|
isLoading: PropTypes.bool,
|
2020-03-04 22:26:01 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 06:33:58 +01:00
|
|
|
componentDidMount() {
|
2020-03-04 22:26:01 +00:00
|
|
|
const { accountId } = this.props
|
|
|
|
|
|
|
|
if (!!accountId && accountId !== -1) {
|
|
|
|
this.props.dispatch(fetchFollowing(accountId))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
if (!!nextProps.accountId && nextProps.accountId !== -1 && nextProps.accountId !== this.props.accountId) {
|
|
|
|
this.props.dispatch(fetchFollowing(nextProps.accountId))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleLoadMore = debounce(() => {
|
|
|
|
const { accountId } = this.props
|
|
|
|
if (!!accountId && accountId !== -1) {
|
|
|
|
this.props.dispatch(expandFollowing(accountId))
|
|
|
|
}
|
|
|
|
}, 300, { leading: true })
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
account,
|
|
|
|
accountIds,
|
|
|
|
hasMore,
|
2020-04-28 06:33:58 +01:00
|
|
|
intl,
|
2020-05-01 06:50:27 +01:00
|
|
|
isLoading,
|
2020-03-04 22:26:01 +00:00
|
|
|
} = this.props
|
|
|
|
|
|
|
|
if (!account) return null
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Block>
|
2020-04-24 04:17:27 +01:00
|
|
|
<div className={[_s.default, _s.px15, _s.py10, _s.justifyContentCenter].join(' ')}>
|
|
|
|
<Heading size='h2'>
|
2020-03-04 22:26:01 +00:00
|
|
|
{intl.formatMessage(messages.follows)}
|
|
|
|
</Heading>
|
|
|
|
</div>
|
2020-04-24 04:17:27 +01:00
|
|
|
<div className={[_s.default, _s.py10].join(' ')}>
|
2020-03-04 22:26:01 +00:00
|
|
|
<ScrollableList
|
|
|
|
scrollKey='following'
|
|
|
|
hasMore={hasMore}
|
2020-05-01 06:50:27 +01:00
|
|
|
isLoading={isLoading}
|
2020-03-04 22:26:01 +00:00
|
|
|
onLoadMore={this.handleLoadMore}
|
|
|
|
emptyMessage={intl.formatMessage(messages.empty)}
|
|
|
|
>
|
|
|
|
{
|
|
|
|
!!accountIds && accountIds.map((id) => (
|
2020-04-29 23:32:49 +01:00
|
|
|
<Account key={`following-${id}`} id={id} compact withBio />
|
2020-03-04 22:26:01 +00:00
|
|
|
))
|
|
|
|
}
|
|
|
|
</ScrollableList>
|
|
|
|
</div>
|
|
|
|
</Block>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|