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

87 lines
2.4 KiB
JavaScript
Raw Normal View History

2020-04-02 17:57:04 +01:00
import { defineMessages, injectIntl } from 'react-intl'
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-04-02 17:57:04 +01:00
import { unblockDomain, fetchDomainBlocks, expandDomainBlocks } from '../actions/domain_blocks'
import ColumnIndicator from '../components/column_indicator'
import List from '../components/list'
const messages = defineMessages({
2020-05-01 06:50:27 +01:00
heading: { id: 'column.domain_blocks', defaultMessage: 'Blocked domains' },
unblockDomain: { id: 'account.unblock_domain', defaultMessage: 'Unblock domain {domain}' },
emptyMessage: { id: 'empty_column.domain_blocks', defaultMessage: 'There are no blocked domains yet.' },
});
2020-04-02 17:57:04 +01:00
const mapDispatchToProps = (dispatch) => ({
onExpandDomainBlocks() {
dispatch(expandDomainBlocks())
},
onFetchDomainBlocks() {
dispatch(fetchDomainBlocks())
},
onUnblockDomain (domain) {
dispatch(unblockDomain(domain))
},
})
2020-04-11 23:29:19 +01:00
const mapStateToProps = (state) => ({
domains: state.getIn(['domain_lists', 'blocks', 'items']),
hasMore: !!state.getIn(['domain_lists', 'blocks', 'next']),
2020-04-02 17:57:04 +01:00
})
2020-02-25 16:04:44 +00:00
export default
@injectIntl
2020-04-02 17:57:04 +01:00
@connect(mapStateToProps, mapDispatchToProps)
class Blocks extends ImmutablePureComponent {
static propTypes = {
2020-04-02 17:57:04 +01:00
intl: PropTypes.object.isRequired,
hasMore: PropTypes.bool,
domains: ImmutablePropTypes.orderedSet,
2020-04-02 17:57:04 +01:00
onUnblockDomain: PropTypes.func.isRequired,
onFetchDomainBlocks: PropTypes.func.isRequired,
onExpandDomainBlocks: PropTypes.func.isRequired,
}
componentWillMount() {
2020-04-02 17:57:04 +01:00
this.props.onFetchDomainBlocks()
}
handleUnblockDomain = (domain) => {
this.props.onUnblockDomain(domain)
}
handleLoadMore = debounce(() => {
2020-04-02 17:57:04 +01:00
this.props.onExpandDomainBlocks()
}, 300, { leading: true })
render() {
2020-04-02 17:57:04 +01:00
const { intl, domains, hasMore } = this.props
if (!domains) {
2020-04-02 17:57:04 +01:00
return <ColumnIndicator type='loading' />
}
2020-04-02 17:57:04 +01:00
const items = domains.map((domain) => {
return {
title: intl.formatMessage(messages.unblockDomain, { domain }),
onClick: () => this.handleUnblockDomain(domain),
hideArrow: true,
}
})
return (
2020-04-02 17:57:04 +01:00
<List
2020-02-24 23:25:55 +00:00
scrollKey='domain_blocks'
onLoadMore={this.handleLoadMore}
hasMore={hasMore}
2020-04-02 17:57:04 +01:00
emptyMessage={intl.formatMessage(messages.emptyMessage)}
items={items}
/>
)
}
}