2022-06-16 12:32:17 -07:00
|
|
|
import debounce from 'lodash/debounce';
|
2022-04-11 12:58:48 -07:00
|
|
|
import React from 'react';
|
|
|
|
import { defineMessages, useIntl, FormattedMessage } from 'react-intl';
|
|
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
|
2022-11-16 05:32:32 -08:00
|
|
|
import { fetchDomainBlocks, expandDomainBlocks } from 'soapbox/actions/domain-blocks';
|
2022-04-11 12:58:48 -07:00
|
|
|
import Domain from 'soapbox/components/domain';
|
2022-11-15 08:00:49 -08:00
|
|
|
import ScrollableList from 'soapbox/components/scrollable-list';
|
2022-04-11 12:58:48 -07:00
|
|
|
import { Spinner } from 'soapbox/components/ui';
|
|
|
|
import { useAppSelector } from 'soapbox/hooks';
|
|
|
|
|
|
|
|
import Column from '../ui/components/column';
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
heading: { id: 'column.domain_blocks', defaultMessage: 'Hidden domains' },
|
|
|
|
unblockDomain: { id: 'account.unblock_domain', defaultMessage: 'Unhide {domain}' },
|
|
|
|
});
|
|
|
|
|
|
|
|
const handleLoadMore = debounce((dispatch) => {
|
|
|
|
dispatch(expandDomainBlocks());
|
|
|
|
}, 300, { leading: true });
|
|
|
|
|
|
|
|
const DomainBlocks: React.FC = () => {
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
const intl = useIntl();
|
|
|
|
|
2022-06-04 00:22:36 -07:00
|
|
|
const domains = useAppSelector((state) => state.domain_lists.blocks.items);
|
|
|
|
const hasMore = useAppSelector((state) => !!state.domain_lists.blocks.next);
|
2022-04-11 12:58:48 -07:00
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
dispatch(fetchDomainBlocks());
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
if (!domains) {
|
|
|
|
return (
|
|
|
|
<Column>
|
|
|
|
<Spinner />
|
|
|
|
</Column>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const emptyMessage = <FormattedMessage id='empty_column.domain_blocks' defaultMessage='There are no hidden domains yet.' />;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Column icon='minus-circle' label={intl.formatMessage(messages.heading)}>
|
|
|
|
<ScrollableList
|
|
|
|
scrollKey='domain_blocks'
|
|
|
|
onLoadMore={() => handleLoadMore(dispatch)}
|
|
|
|
hasMore={hasMore}
|
|
|
|
emptyMessage={emptyMessage}
|
2022-11-17 07:10:18 -08:00
|
|
|
className='divide-y divide-gray-200 dark:divide-gray-800'
|
2022-04-11 12:58:48 -07:00
|
|
|
>
|
2022-11-17 07:10:18 -08:00
|
|
|
{['gab.com', 'gab.ai'].map((domain) =>
|
2022-04-11 12:58:48 -07:00
|
|
|
<Domain key={domain} domain={domain} />,
|
|
|
|
)}
|
|
|
|
</ScrollableList>
|
|
|
|
</Column>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default DomainBlocks;
|