1
0
mirror of https://github.com/funamitech/mastodon synced 2024-12-13 14:18:34 +09:00
YuruToot/app/javascript/flavours/glitch/features/domain_blocks/index.jsx

88 lines
2.6 KiB
React
Raw Normal View History

2018-03-05 05:46:27 +09:00
import PropTypes from 'prop-types';
import { defineMessages, injectIntl, FormattedMessage } from 'react-intl';
import { Helmet } from 'react-helmet';
import ImmutablePropTypes from 'react-immutable-proptypes';
2018-03-05 05:46:27 +09:00
import ImmutablePureComponent from 'react-immutable-pure-component';
import { connect } from 'react-redux';
import { debounce } from 'lodash';
import { fetchDomainBlocks, expandDomainBlocks } from '../../actions/domain_blocks';
import ColumnBackButtonSlim from '../../components/column_back_button_slim';
import { LoadingIndicator } from '../../components/loading_indicator';
import ScrollableList from '../../components/scrollable_list';
import DomainContainer from '../../containers/domain_container';
import Column from '../ui/components/column';
2018-03-05 05:46:27 +09:00
const messages = defineMessages({
heading: { id: 'column.domain_blocks', defaultMessage: 'Blocked domains' },
unblockDomain: { id: 'account.unblock_domain', defaultMessage: 'Unblock domain {domain}' },
2018-03-05 05:46:27 +09:00
});
const mapStateToProps = state => ({
domains: state.getIn(['domain_lists', 'blocks', 'items']),
hasMore: !!state.getIn(['domain_lists', 'blocks', 'next']),
2018-03-05 05:46:27 +09:00
});
class Blocks extends ImmutablePureComponent {
2018-03-05 05:46:27 +09:00
static propTypes = {
params: PropTypes.object.isRequired,
dispatch: PropTypes.func.isRequired,
hasMore: PropTypes.bool,
2018-03-05 05:46:27 +09:00
domains: ImmutablePropTypes.list,
intl: PropTypes.object.isRequired,
multiColumn: PropTypes.bool,
2018-03-05 05:46:27 +09:00
};
UNSAFE_componentWillMount () {
2018-03-05 05:46:27 +09:00
this.props.dispatch(fetchDomainBlocks());
}
handleLoadMore = debounce(() => {
this.props.dispatch(expandDomainBlocks());
}, 300, { leading: true });
render () {
const { intl, domains, hasMore, multiColumn } = this.props;
2018-03-05 05:46:27 +09:00
if (!domains) {
return (
<Column>
<LoadingIndicator />
</Column>
);
}
const emptyMessage = <FormattedMessage id='empty_column.domain_blocks' defaultMessage='There are no blocked domains yet.' />;
2018-03-05 05:46:27 +09:00
return (
<Column bindToDocument={!multiColumn} icon='minus-circle' heading={intl.formatMessage(messages.heading)}>
2018-03-05 05:46:27 +09:00
<ColumnBackButtonSlim />
<ScrollableList
scrollKey='domain_blocks'
onLoadMore={this.handleLoadMore}
hasMore={hasMore}
emptyMessage={emptyMessage}
bindToDocument={!multiColumn}
>
2018-03-05 05:46:27 +09:00
{domains.map(domain =>
<DomainContainer key={domain} domain={domain} />,
2018-03-05 05:46:27 +09:00
)}
</ScrollableList>
<Helmet>
<meta name='robots' content='noindex' />
</Helmet>
2018-03-05 05:46:27 +09:00
</Column>
);
}
}
export default connect(mapStateToProps)(injectIntl(Blocks));