bigbuffet-rw/app/soapbox/features/ui/components/modals/embed-modal.tsx

58 lines
1.5 KiB
TypeScript
Raw Normal View History

2022-08-21 09:37:14 -07:00
import React, { useEffect } from 'react';
2022-05-03 14:43:04 -07:00
import { FormattedMessage } from 'react-intl';
2022-08-22 10:08:30 -07:00
import { closeModal } from 'soapbox/actions/modals';
import CopyableInput from 'soapbox/components/copyable-input';
import SafeEmbed from 'soapbox/components/safe-embed';
import { Modal, Stack, Text, Divider } from 'soapbox/components/ui';
2022-08-22 10:08:30 -07:00
import { useAppDispatch } from 'soapbox/hooks';
2022-08-21 09:37:14 -07:00
import useEmbed from 'soapbox/queries/embed';
2022-05-03 14:43:04 -07:00
interface IEmbedModal {
2022-08-21 08:21:25 -07:00
url: string,
onError: (error: any) => void,
2022-05-03 14:43:04 -07:00
}
2022-08-21 08:21:25 -07:00
const EmbedModal: React.FC<IEmbedModal> = ({ url, onError }) => {
2022-08-22 10:08:30 -07:00
const dispatch = useAppDispatch();
2022-08-21 09:37:14 -07:00
const { data: embed, error, isError } = useEmbed(url);
2022-08-21 08:21:25 -07:00
useEffect(() => {
2022-08-21 09:37:14 -07:00
if (error && isError) {
2022-08-21 08:21:25 -07:00
onError(error);
2022-08-21 09:37:14 -07:00
}
}, [isError]);
2022-05-03 14:43:04 -07:00
2022-08-22 10:08:30 -07:00
const handleClose = () => {
dispatch(closeModal('EMBED'));
};
2022-05-03 14:43:04 -07:00
return (
2022-08-22 10:08:30 -07:00
<Modal
title={<FormattedMessage id='status.embed' defaultMessage='Embed post' />}
onClose={handleClose}
>
2022-05-03 14:43:04 -07:00
<Stack space={4}>
2022-08-22 10:08:30 -07:00
<Text theme='muted'>
<FormattedMessage id='embed.instructions' defaultMessage='Embed this post on your website by copying the code below.' />
</Text>
<CopyableInput value={embed?.html || ''} />
2022-05-03 14:43:04 -07:00
</Stack>
2022-08-22 10:08:30 -07:00
2022-08-23 08:40:39 -07:00
<div className='py-9'>
<Divider />
</div>
2022-08-22 10:08:30 -07:00
<SafeEmbed
className='rounded-xl overflow-hidden w-full'
sandbox='allow-same-origin allow-scripts'
title='embedded-status'
html={embed?.html}
/>
2022-05-03 14:43:04 -07:00
</Modal>
);
};
export default EmbedModal;