2020-03-24 04:39:12 +00:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl'
|
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-06-09 21:47:12 +01:00
|
|
|
import { me } from '../initial_state'
|
2020-03-04 22:26:01 +00:00
|
|
|
import { fetchBlocks, expandBlocks } from '../actions/blocks'
|
2020-04-11 23:29:19 +01:00
|
|
|
import Account from '../components/account'
|
2020-06-09 21:47:12 +01:00
|
|
|
import Block from '../components/block'
|
2020-06-10 17:08:31 +01:00
|
|
|
import Heading from '../components/heading'
|
2020-03-04 22:26:01 +00:00
|
|
|
import ScrollableList from '../components/scrollable_list'
|
2019-08-07 06:02:36 +01:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
2020-03-24 04:39:12 +00:00
|
|
|
empty: { id: 'empty_column.blocks', defaultMessage: 'You haven\'t blocked any users yet.' },
|
2020-06-10 17:08:31 +01:00
|
|
|
blocks: { id: 'navigation_bar.blocks', defaultMessage: 'Blocked users' },
|
2020-03-24 04:39:12 +00:00
|
|
|
})
|
2019-08-07 06:02:36 +01:00
|
|
|
|
2020-04-11 23:29:19 +01:00
|
|
|
const mapStateToProps = (state) => ({
|
2020-06-09 21:47:12 +01:00
|
|
|
accountIds: state.getIn(['user_lists', 'blocks', me, 'items']),
|
|
|
|
hasMore: !!state.getIn(['user_lists', 'blocks', me, 'next']),
|
|
|
|
isLoading: state.getIn(['user_lists', 'blocks', me, 'isLoading']),
|
|
|
|
})
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
2020-06-10 17:08:31 +01:00
|
|
|
onFetchBlocks: () => dispatch(fetchBlocks()),
|
|
|
|
onExpandBlocks: () => dispatch(expandBlocks()),
|
2020-03-24 04:39:12 +00:00
|
|
|
})
|
2019-08-07 06:02:36 +01:00
|
|
|
|
2020-02-25 16:04:44 +00:00
|
|
|
export default
|
2020-06-09 21:47:12 +01:00
|
|
|
@connect(mapStateToProps, mapDispatchToProps)
|
2019-08-07 06:02:36 +01:00
|
|
|
@injectIntl
|
|
|
|
class Blocks extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
accountIds: ImmutablePropTypes.list,
|
|
|
|
hasMore: PropTypes.bool,
|
|
|
|
intl: PropTypes.object.isRequired,
|
2020-06-09 21:47:12 +01:00
|
|
|
isLoading: PropTypes.bool,
|
|
|
|
onExpandBlocks: PropTypes.func.isRequired,
|
|
|
|
onFetchBlocks: PropTypes.func.isRequired,
|
2020-03-24 04:39:12 +00:00
|
|
|
}
|
2019-08-07 06:02:36 +01:00
|
|
|
|
2020-06-09 21:47:12 +01:00
|
|
|
componentDidMount() {
|
|
|
|
this.props.onFetchBlocks()
|
2019-08-07 06:02:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
handleLoadMore = debounce(() => {
|
2020-06-09 21:47:12 +01:00
|
|
|
this.props.onExpandBlocks()
|
2020-03-24 04:39:12 +00:00
|
|
|
}, 300, { leading: true })
|
2019-08-07 06:02:36 +01:00
|
|
|
|
2020-03-24 04:39:12 +00:00
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
intl,
|
|
|
|
accountIds,
|
2020-05-01 06:50:27 +01:00
|
|
|
hasMore,
|
|
|
|
isLoading,
|
2020-03-24 04:39:12 +00:00
|
|
|
} = this.props
|
2019-08-07 06:02:36 +01:00
|
|
|
|
2020-03-24 04:39:12 +00:00
|
|
|
const emptyMessage = intl.formatMessage(messages.empty)
|
|
|
|
|
2019-08-07 06:02:36 +01:00
|
|
|
return (
|
2020-06-09 21:47:12 +01:00
|
|
|
<Block>
|
2020-06-10 17:08:31 +01:00
|
|
|
<div className={[_s.default, _s.px15, _s.py10, _s.justifyContentCenter].join(' ')}>
|
|
|
|
<Heading size='h2'>
|
|
|
|
{intl.formatMessage(messages.blocks)}
|
|
|
|
</Heading>
|
|
|
|
</div>
|
2020-06-09 21:47:12 +01:00
|
|
|
<ScrollableList
|
|
|
|
scrollKey='blocked_accounts'
|
|
|
|
onLoadMore={this.handleLoadMore}
|
|
|
|
hasMore={hasMore}
|
|
|
|
isLoading={isLoading}
|
|
|
|
emptyMessage={emptyMessage}
|
|
|
|
>
|
|
|
|
{
|
2020-06-10 21:05:15 +01:00
|
|
|
accountIds && accountIds.map((id) =>
|
2020-06-09 21:47:12 +01:00
|
|
|
<Account
|
|
|
|
key={`blocked-accounts-${id}`}
|
|
|
|
id={id}
|
|
|
|
compact
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
</ScrollableList>
|
|
|
|
</Block>
|
2020-03-24 04:39:12 +00:00
|
|
|
)
|
2019-08-07 06:02:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|