import PropTypes from 'prop-types'; import { defineMessages, FormattedMessage, injectIntl } from 'react-intl'; import ImmutablePureComponent from 'react-immutable-pure-component'; import CloseIcon from 'mastodon/../material-icons/400-24px/close.svg?react'; import api from 'mastodon/api'; import { IconButton } from 'mastodon/components/icon_button'; const messages = defineMessages({ close: { id: 'lightbox.close', defaultMessage: 'Close' }, }); class EmbedModal extends ImmutablePureComponent { static propTypes = { id: PropTypes.string.isRequired, onClose: PropTypes.func.isRequired, onError: PropTypes.func.isRequired, intl: PropTypes.object.isRequired, }; state = { loading: false, oembed: null, }; componentDidMount () { const { id } = this.props; this.setState({ loading: true }); api().get(`/api/web/embeds/${id}`).then(res => { this.setState({ loading: false, oembed: res.data }); const iframeDocument = this.iframe.contentWindow.document; iframeDocument.open(); iframeDocument.write(res.data.html); iframeDocument.close(); iframeDocument.body.style.margin = 0; this.iframe.width = iframeDocument.body.scrollWidth; this.iframe.height = iframeDocument.body.scrollHeight; }).catch(error => { this.props.onError(error); }); } setIframeRef = c => { this.iframe = c; }; handleTextareaClick = (e) => { e.target.select(); }; render () { const { intl, onClose } = this.props; const { oembed } = this.state; return (