import { useEffect, useMemo, useState } from '@wordpress/element'; import { __ } from '@wordpress/i18n'; import { useUi } from '../runtime'; import { PhoneFrame, PhoneInbox } from './InboxPreview'; /** * A campaign's HTML as a sandboxed blob address, wrapped in a document when * it is only a fragment. * * @param {string} html The campaign's `content_html`. * @return {string} A blob URL, or '' when there is no content. */ function useEmailUrl( html ) { const url = useMemo( () => { if ( ! html ) { return ''; } const lower = html.trim().toLowerCase(); const doc = lower.startsWith( '' + html + ''; return URL.createObjectURL( new Blob( [ doc ], { type: 'text/html' } ) ); }, [ html ] ); useEffect( () => () => url && URL.revokeObjectURL( url ), [ url ] ); return url; } /** * A small, still picture of the email for a summary row. * * @param {Object} props * @param {string} props.html The campaign's `content_html`. */ export function EmailThumb( { html } ) { const url = useEmailUrl( html ); if ( ! url ) { return null; } return (