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

69 lines
1.8 KiB
JavaScript
Raw Normal View History

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-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-03-04 22:26:01 +00:00
import ScrollableList from '../components/scrollable_list'
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-04-11 23:29:19 +01:00
const mapStateToProps = (state) => ({
accountIds: state.getIn(['user_lists', 'blocks', 'items']),
hasMore: !!state.getIn(['user_lists', 'blocks', 'next']),
2020-05-01 06:50:27 +01:00
isLoading: state.getIn(['user_lists', 'blocks', 'isLoading'], true),
2020-03-24 04:39:12 +00:00
})
2020-02-25 16:04:44 +00:00
export default
@connect(mapStateToProps)
@injectIntl
class Blocks extends ImmutablePureComponent {
static propTypes = {
params: PropTypes.object.isRequired,
dispatch: PropTypes.func.isRequired,
accountIds: ImmutablePropTypes.list,
hasMore: PropTypes.bool,
2020-05-01 06:50:27 +01:00
isLoading: PropTypes.bool,
intl: PropTypes.object.isRequired,
2020-03-24 04:39:12 +00:00
}
2020-03-24 04:39:12 +00:00
componentWillMount() {
this.props.dispatch(fetchBlocks())
}
handleLoadMore = debounce(() => {
2020-03-24 04:39:12 +00:00
this.props.dispatch(expandBlocks())
}, 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 (
2020-02-24 23:25:55 +00:00
<ScrollableList
scrollKey='blocks'
onLoadMore={this.handleLoadMore}
hasMore={hasMore}
2020-03-24 04:39:12 +00:00
emptyMessage={emptyMessage}
2020-05-01 06:50:27 +01:00
isLoading={isLoading}
2020-02-24 23:25:55 +00:00
>
2020-03-24 04:39:12 +00:00
{
2020-05-01 06:50:27 +01:00
!!accountIds && accountIds.map(id =>
2020-04-11 23:29:19 +01:00
<Account key={`blocked-${id}`} id={id} compact />
2020-03-24 04:39:12 +00:00
)
}
2020-02-24 23:25:55 +00:00
</ScrollableList>
2020-03-24 04:39:12 +00:00
)
}
}