gab-social/app/javascript/gabsocial/features/blocked_accounts.js

90 lines
2.6 KiB
JavaScript
Raw Normal View History

import React from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
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'
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'
import Block from '../components/block'
import BlockHeading from '../components/block_heading'
2020-03-04 22:26:01 +00:00
import ScrollableList from '../components/scrollable_list'
2020-11-25 21:22:37 +00:00
import AccountPlaceholder from '../components/placeholder/account_placeholder'
class Blocks extends ImmutablePureComponent {
componentDidMount() {
this.props.onFetchBlocks()
}
handleLoadMore = debounce(() => {
this.props.onExpandBlocks()
2020-03-24 04:39:12 +00:00
}, 300, { leading: true })
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
2020-03-24 04:39:12 +00:00
const emptyMessage = intl.formatMessage(messages.empty)
return (
<Block>
<BlockHeading title={intl.formatMessage(messages.blocks)} />
<ScrollableList
scrollKey='blocked_accounts'
onLoadMore={this.handleLoadMore}
hasMore={hasMore}
isLoading={isLoading}
2020-11-25 21:22:37 +00:00
showLoading={isLoading}
emptyMessage={emptyMessage}
2020-11-25 21:22:37 +00:00
placeholderComponent={AccountPlaceholder}
placeholderCount={3}
>
{
2020-11-25 21:22:37 +00:00
accountIds && accountIds.map((id) => (
<Account
key={`blocked-accounts-${id}`}
id={id}
compact
/>
2020-11-25 21:22:37 +00:00
))
}
</ScrollableList>
</Block>
2020-03-24 04:39:12 +00:00
)
}
}
const messages = defineMessages({
empty: { id: 'empty_column.blocks', defaultMessage: 'You haven\'t blocked any users yet.' },
blocks: { id: 'navigation_bar.blocks', defaultMessage: 'Blocked users' },
})
const mapStateToProps = (state) => ({
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) => ({
onFetchBlocks: () => dispatch(fetchBlocks()),
onExpandBlocks: () => dispatch(expandBlocks()),
})
Blocks.propTypes = {
accountIds: ImmutablePropTypes.list,
hasMore: PropTypes.bool,
intl: PropTypes.object.isRequired,
isLoading: PropTypes.bool,
onExpandBlocks: PropTypes.func.isRequired,
onFetchBlocks: PropTypes.func.isRequired,
}
export default injectIntl(connect(mapStateToProps, mapDispatchToProps)(Blocks))