import React, { useCallback, useEffect, useState } from 'react'; import { useHistory } from 'react-router-dom'; import { fetchStatus } from 'soapbox/actions/statuses'; import MissingIndicator from 'soapbox/components/missing-indicator'; import SiteLogo from 'soapbox/components/site-logo'; import Status from 'soapbox/components/status'; import { Spinner } from 'soapbox/components/ui'; import { useAppDispatch, useAppSelector } from 'soapbox/hooks'; import { iframeId } from 'soapbox/iframe'; import { makeGetStatus } from 'soapbox/selectors'; interface IEmbeddedStatus { params: { statusId: string, }, } /** Status to be presented in an iframe for embeds on external websites. */ const EmbeddedStatus: React.FC = ({ params }) => { const dispatch = useAppDispatch(); const history = useHistory(); const getStatus = useCallback(makeGetStatus(), []); const status = useAppSelector(state => getStatus(state, { id: params.statusId })); const [loading, setLoading] = useState(true); useEffect(() => { // Prevent navigation for UX and security. // https://stackoverflow.com/a/71531211 history.block(); dispatch(fetchStatus(params.statusId)) .then(() => setLoading(false)) .catch(() => setLoading(false)); }, []); useEffect(() => { window.parent.postMessage({ type: 'setHeight', id: iframeId, height: document.getElementsByTagName('html')[0].scrollHeight, }, '*'); }, [status, loading]); const logo = (
); const renderInner = () => { if (loading) { return ; } else if (status) { return ; } else { return ; } }; return ( e.stopPropagation()} target='_blank' >
{renderInner()}
); }; export default EmbeddedStatus;