import React, { useState, useEffect } from 'react'; import { FormattedMessage } from 'react-intl'; import api from 'soapbox/api'; import SafeEmbed from 'soapbox/components/safe-embed'; import { Modal, Stack, Text, Input } from 'soapbox/components/ui'; import { useAppDispatch } from 'soapbox/hooks'; import type { RootState } from 'soapbox/store'; const fetchEmbed = (url: string) => { return (dispatch: any, getState: () => RootState) => { return api(getState).get('/api/oembed', { params: { url } }); }; }; interface IEmbedModal { url: string, onError: (error: any) => void, } const EmbedModal: React.FC = ({ url, onError }) => { const dispatch = useAppDispatch(); const [html, setHtml] = useState(''); useEffect(() => { dispatch(fetchEmbed(url)).then(({ data }) => { if (data?.html) { setHtml(data.html); } }).catch(error => { onError(error); }); }, []); const handleInputClick: React.MouseEventHandler = (e) => { e.currentTarget.select(); }; return ( }> ); }; export default EmbedModal;