2017-08-31 10:38:35 +09:00
|
|
|
import PropTypes from 'prop-types';
|
2023-05-28 23:38:10 +09:00
|
|
|
|
2019-10-03 10:17:29 +09:00
|
|
|
import { defineMessages, FormattedMessage, injectIntl } from 'react-intl';
|
2023-05-28 23:38:10 +09:00
|
|
|
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
|
|
|
|
2023-10-25 02:45:08 +09:00
|
|
|
import { ReactComponent as CloseIcon } from '@material-symbols/svg-600/outlined/close.svg';
|
|
|
|
|
2022-10-11 17:32:31 +09:00
|
|
|
import api from 'flavours/glitch/api';
|
2023-05-09 10:11:56 +09:00
|
|
|
import { IconButton } from 'flavours/glitch/components/icon_button';
|
2019-10-03 10:17:29 +09:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
close: { id: 'lightbox.close', defaultMessage: 'Close' },
|
|
|
|
});
|
2017-08-31 10:38:35 +09:00
|
|
|
|
2019-09-09 22:16:08 +09:00
|
|
|
class EmbedModal extends ImmutablePureComponent {
|
2017-08-31 10:38:35 +09:00
|
|
|
|
|
|
|
static propTypes = {
|
2023-07-13 22:53:03 +09:00
|
|
|
id: PropTypes.string.isRequired,
|
2017-08-31 10:38:35 +09:00
|
|
|
onClose: PropTypes.func.isRequired,
|
2019-02-11 05:28:29 +09:00
|
|
|
onError: PropTypes.func.isRequired,
|
2017-08-31 10:38:35 +09:00
|
|
|
intl: PropTypes.object.isRequired,
|
2023-02-04 04:52:07 +09:00
|
|
|
};
|
2017-08-31 10:38:35 +09:00
|
|
|
|
|
|
|
state = {
|
|
|
|
loading: false,
|
|
|
|
oembed: null,
|
|
|
|
};
|
|
|
|
|
|
|
|
componentDidMount () {
|
2023-07-13 22:53:03 +09:00
|
|
|
const { id } = this.props;
|
2017-08-31 10:38:35 +09:00
|
|
|
|
|
|
|
this.setState({ loading: true });
|
|
|
|
|
2023-07-13 22:53:03 +09:00
|
|
|
api().get(`/api/web/embeds/${id}`).then(res => {
|
2017-08-31 10:38:35 +09:00
|
|
|
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;
|
2017-09-09 23:23:44 +09:00
|
|
|
this.iframe.width = iframeDocument.body.scrollWidth;
|
|
|
|
this.iframe.height = iframeDocument.body.scrollHeight;
|
2019-02-11 05:28:29 +09:00
|
|
|
}).catch(error => {
|
|
|
|
this.props.onError(error);
|
2017-08-31 10:38:35 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
setIframeRef = c => {
|
|
|
|
this.iframe = c;
|
2023-02-04 04:52:07 +09:00
|
|
|
};
|
2017-08-31 10:38:35 +09:00
|
|
|
|
|
|
|
handleTextareaClick = (e) => {
|
|
|
|
e.target.select();
|
2023-02-04 04:52:07 +09:00
|
|
|
};
|
2017-08-31 10:38:35 +09:00
|
|
|
|
|
|
|
render () {
|
2019-10-03 10:17:29 +09:00
|
|
|
const { intl, onClose } = this.props;
|
2017-08-31 10:38:35 +09:00
|
|
|
const { oembed } = this.state;
|
|
|
|
|
|
|
|
return (
|
2019-10-03 10:17:29 +09:00
|
|
|
<div className='modal-root__modal report-modal embed-modal'>
|
|
|
|
<div className='report-modal__target'>
|
2023-10-25 02:45:08 +09:00
|
|
|
<IconButton className='media-modal__close' title={intl.formatMessage(messages.close)} icon='times' iconComponent={CloseIcon} onClick={onClose} size={16} />
|
2019-10-03 10:17:29 +09:00
|
|
|
<FormattedMessage id='status.embed' defaultMessage='Embed' />
|
|
|
|
</div>
|
2017-08-31 10:38:35 +09:00
|
|
|
|
2019-10-03 10:17:29 +09:00
|
|
|
<div className='report-modal__container embed-modal__container' style={{ display: 'block' }}>
|
2017-08-31 10:38:35 +09:00
|
|
|
<p className='hint'>
|
|
|
|
<FormattedMessage id='embed.instructions' defaultMessage='Embed this status on your website by copying the code below.' />
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<input
|
|
|
|
type='text'
|
|
|
|
className='embed-modal__html'
|
|
|
|
readOnly
|
|
|
|
value={oembed && oembed.html || ''}
|
|
|
|
onClick={this.handleTextareaClick}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<p className='hint'>
|
|
|
|
<FormattedMessage id='embed.preview' defaultMessage='Here is what it will look like:' />
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<iframe
|
|
|
|
className='embed-modal__iframe'
|
|
|
|
frameBorder='0'
|
|
|
|
ref={this.setIframeRef}
|
2023-05-23 04:18:21 +09:00
|
|
|
sandbox='allow-scripts allow-same-origin'
|
2017-08-31 10:38:35 +09:00
|
|
|
title='preview'
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-03-25 07:15:25 +09:00
|
|
|
|
|
|
|
export default injectIntl(EmbedModal);
|