import React from 'react' import PropTypes from 'prop-types' import ImmutablePureComponent from 'react-immutable-pure-component' import { defineMessages, injectIntl } from 'react-intl' import api from '../../api' import ModalLayout from './modal_layout' import Divider from '../divider' import Icon from '../icon' import Input from '../input' import Text from '../text' class EmbedModal extends ImmutablePureComponent { state = { loading: false, oembed: null, } componentDidMount() { const { url } = this.props this.setState({ loading: true }) api().post('/api/web/embed', { url }).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 (
{intl.formatMessage(messages.instructions)}
{intl.formatMessage(messages.preview)}