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'
|
2019-08-07 06:02:36 +01:00
|
|
|
|
|
|
|
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.' },
|
2019-08-07 06:02:36 +01:00
|
|
|
});
|
|
|
|
|
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) => ({
|
2019-08-07 06:02:36 +01:00
|
|
|
domains: state.getIn(['domain_lists', 'blocks', 'items']),
|
|
|
|
hasMore: !!state.getIn(['domain_lists', 'blocks', 'next']),
|
2020-04-02 17:57:04 +01:00
|
|
|
})
|
2019-08-07 06:02:36 +01:00
|
|
|
|
2020-02-25 16:04:44 +00:00
|
|
|
export default
|
2019-08-07 06:02:36 +01:00
|
|
|
@injectIntl
|
2020-04-02 17:57:04 +01:00
|
|
|
@connect(mapStateToProps, mapDispatchToProps)
|
2019-08-07 06:02:36 +01:00
|
|
|
class Blocks extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
2020-04-02 17:57:04 +01:00
|
|
|
intl: PropTypes.object.isRequired,
|
2019-08-07 06:02:36 +01:00
|
|
|
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,
|
|
|
|
}
|
2019-08-07 06:02:36 +01:00
|
|
|
|
|
|
|
componentWillMount() {
|
2020-04-02 17:57:04 +01:00
|
|
|
this.props.onFetchDomainBlocks()
|
|
|
|
}
|
|
|
|
|
|
|
|
handleUnblockDomain = (domain) => {
|
|
|
|
this.props.onUnblockDomain(domain)
|
2019-08-07 06:02:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
handleLoadMore = debounce(() => {
|
2020-04-02 17:57:04 +01:00
|
|
|
this.props.onExpandDomainBlocks()
|
|
|
|
}, 300, { leading: true })
|
2019-08-07 06:02:36 +01:00
|
|
|
|
|
|
|
render() {
|
2020-04-02 17:57:04 +01:00
|
|
|
const { intl, domains, hasMore } = this.props
|
2019-08-07 06:02:36 +01:00
|
|
|
|
|
|
|
if (!domains) {
|
2020-04-02 17:57:04 +01:00
|
|
|
return <ColumnIndicator type='loading' />
|
2019-08-07 06:02:36 +01:00
|
|
|
}
|
|
|
|
|
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,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-08-07 06:02:36 +01:00
|
|
|
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}
|
|
|
|
/>
|
|
|
|
)
|
2019-08-07 06:02:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|