import { useCallback, useEffect, useState } from 'react'; import { FormattedMessage } from 'react-intl'; import CampaignIcon from '@/material-icons/400-24px/campaign.svg?react'; import DomainDisabledIcon from '@/material-icons/400-24px/domain_disabled.svg?react'; import HistoryIcon from '@/material-icons/400-24px/history.svg?react'; import PersonRemoveIcon from '@/material-icons/400-24px/person_remove.svg?react'; import ReplyIcon from '@/material-icons/400-24px/reply.svg?react'; import VisibilityOffIcon from '@/material-icons/400-24px/visibility_off.svg?react'; import { blockAccount } from 'mastodon/actions/accounts'; import { blockDomain } from 'mastodon/actions/domain_blocks'; import { closeModal } from 'mastodon/actions/modal'; import { apiRequest } from 'mastodon/api'; import { Button } from 'mastodon/components/button'; import { Icon } from 'mastodon/components/icon'; import { LoadingIndicator } from 'mastodon/components/loading_indicator'; import { ShortNumber } from 'mastodon/components/short_number'; import { useAppDispatch } from 'mastodon/store'; interface DomainBlockPreviewResponse { following_count: number; followers_count: number; } export const DomainBlockModal: React.FC<{ domain: string; accountId: string; acct: string; }> = ({ domain, accountId, acct }) => { const dispatch = useAppDispatch(); const [loading, setLoading] = useState(true); const [preview, setPreview] = useState( null, ); const handleClick = useCallback(() => { if (loading) { return; // Prevent destructive action before the preview finishes loading or times out } dispatch(closeModal({ modalType: undefined, ignoreFocus: false })); dispatch(blockDomain(domain)); }, [dispatch, loading, domain]); const handleSecondaryClick = useCallback(() => { dispatch(closeModal({ modalType: undefined, ignoreFocus: false })); dispatch(blockAccount(accountId)); }, [dispatch, accountId]); const handleCancel = useCallback(() => { dispatch(closeModal({ modalType: undefined, ignoreFocus: false })); }, [dispatch]); useEffect(() => { setLoading(true); apiRequest('GET', 'v1/domain_blocks/preview', { params: { domain }, timeout: 5000, }) .then((data) => { setPreview(data); setLoading(false); return ''; }) .catch(() => { setLoading(false); }); }, [setPreview, setLoading, domain]); return (

{domain}
{preview && preview.followers_count + preview.following_count > 0 && (
), followingCount: preview.following_count, followingCountDisplay: ( ), }} />
)}
); }; // eslint-disable-next-line import/no-default-export export default DomainBlockModal;