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-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 {
|
|
|
|
fetchFollowers,
|
|
|
|
expandFollowers,
|
|
|
|
} 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'
|
2020-08-07 05:14:13 +01:00
|
|
|
import BlockHeading from '../components/block_heading'
|
2020-07-29 21:40:47 +01:00
|
|
|
import AccountPlaceholder from '../components/placeholder/account_placeholder'
|
2020-03-04 22:26:01 +00:00
|
|
|
|
|
|
|
class Followers extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
componentWillMount() {
|
|
|
|
const { accountId } = this.props
|
|
|
|
|
|
|
|
if (accountId && accountId !== -1) {
|
|
|
|
this.props.dispatch(fetchFollowers(accountId))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
if (!!nextProps.accountId && nextProps.accountId !== -1 && nextProps.accountId !== this.props.accountId) {
|
|
|
|
this.props.dispatch(fetchFollowers(nextProps.accountId))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleLoadMore = debounce(() => {
|
|
|
|
const { accountId } = this.props
|
|
|
|
if (!!accountId && accountId !== -1) {
|
|
|
|
this.props.dispatch(expandFollowers(accountId))
|
|
|
|
}
|
|
|
|
}, 300, { leading: true })
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
account,
|
|
|
|
accountIds,
|
|
|
|
hasMore,
|
2020-05-01 06:50:27 +01:00
|
|
|
intl,
|
|
|
|
isLoading,
|
2020-03-04 22:26:01 +00:00
|
|
|
} = this.props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Block>
|
2020-08-07 05:14:13 +01:00
|
|
|
<BlockHeading title={intl.formatMessage(messages.followers)} />
|
|
|
|
<ScrollableList
|
|
|
|
scrollKey='followers'
|
|
|
|
hasMore={hasMore}
|
|
|
|
isLoading={isLoading}
|
|
|
|
onLoadMore={this.handleLoadMore}
|
|
|
|
placeholderComponent={AccountPlaceholder}
|
|
|
|
placeholderCount={4}
|
|
|
|
emptyMessage={intl.formatMessage(messages.empty)}
|
|
|
|
>
|
|
|
|
{
|
|
|
|
account && accountIds && accountIds.map((id) => (
|
|
|
|
<Account key={`follower-${id}`} id={id} compact withBio />
|
|
|
|
))
|
|
|
|
}
|
|
|
|
</ScrollableList>
|
2020-03-04 22:26:01 +00:00
|
|
|
</Block>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-08-19 01:22:15 +01:00
|
|
|
|
|
|
|
const mapStateToProps = (state, { account }) => {
|
|
|
|
const accountId = !!account ? account.get('id') : -1
|
|
|
|
|
|
|
|
return {
|
|
|
|
accountId,
|
|
|
|
accountIds: state.getIn(['user_lists', 'followers', accountId, 'items']),
|
|
|
|
hasMore: !!state.getIn(['user_lists', 'followers', accountId, 'next']),
|
|
|
|
isLoading: state.getIn(['user_lists', 'followers', accountId, 'isLoading'], true),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
followers: { id: 'account.followers', defaultMessage: 'Followers' },
|
|
|
|
empty: { id: 'account.followers.empty', defaultMessage: 'No one follows this user yet.' },
|
|
|
|
})
|
|
|
|
|
|
|
|
Followers.propTypes = {
|
|
|
|
account: ImmutablePropTypes.map,
|
|
|
|
accountId: PropTypes.string,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
params: PropTypes.object.isRequired,
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
|
|
|
accountIds: ImmutablePropTypes.list,
|
|
|
|
hasMore: PropTypes.bool,
|
|
|
|
isLoading: PropTypes.bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default injectIntl(connect(mapStateToProps)(Followers))
|