Back

100% Statements 4/4
43.47% Branches 10/23
100% Functions 2/2
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100                    2x                     1x   1x                   1x                                                                                                                                    
import { __ } from '@wordpress/i18n';
import { baseDomain, preparePreviewText } from '../helpers';
import { ExpandableText } from '../shared/expandable-text';
import { MediaImage } from '../shared/media-image';
import { tumblrTitle, tumblrDescription } from './helpers';
import TumblrPostActions from './post/actions';
import TumblrPostHeader from './post/header';
import type { TumblrPreviewProps } from './types';
import './styles.scss';
 
export const TumblrPostPreview: React.FC< TumblrPreviewProps > = ( {
	title,
	description,
	image,
	user,
	url,
	media,
	cardTitle,
	hyperlinks,
	imageFocalPoint,
} ) => {
	const hasMedia = !! media?.length;
 
	return (
		<div className="tumblr-preview__post">
			<div className="tumblr-preview__card">
				<TumblrPostHeader user={ user } />
				<div className="tumblr-preview__body">
					{ title ? <div className="tumblr-preview__title">{ tumblrTitle( title ) }</div> : null }
					{ description && (
						<div className="tumblr-preview__description">
							<ExpandableText text={ description }>
								{ visibleText =>
									preparePreviewText( tumblrDescription( visibleText ), {
										platform: 'tumblr',
										hyperlinks,
									} )
								}
							</ExpandableText>
						</div>
					) }
					{ hasMedia ? (
						<>
							<div className="tumblr-preview__media-item">
								{ media[ 0 ].type.startsWith( 'video/' ) ? (
									<video controls>
										<source src={ media[ 0 ].url } type={ media[ 0 ].type } />
									</video>
								) : (
									<img
										className="tumblr-preview__image"
										src={ media[ 0 ].url }
										alt={ media[ 0 ].alt || '' }
									/>
								) }
							</div>
							{ url && (
								<div className="tumblr-preview__view-link">
									<a href={ url } target="_blank" rel="noreferrer">
										{ __( 'View On WordPress', 'social-previews' ) }
									</a>
								</div>
							) }
						</>
					) : (
						url && (
							<div className="tumblr-preview__window">
								{ image && (
									<div className="tumblr-preview__window-top">
										<MediaImage
											className="tumblr-preview__image"
											src={ image }
											alt={ __( 'Tumblr preview thumbnail', 'social-previews' ) }
											focalPoint={ imageFocalPoint }
										/>
										{ cardTitle && (
											<div className="tumblr-preview__overlay">
												<div className="tumblr-preview__overlay-title">
													{ tumblrTitle( cardTitle ) }
												</div>
											</div>
										) }
									</div>
								) }
								<div className={ `tumblr-preview__window-bottom ${ ! image ? 'is-full' : '' }` }>
									{ ! image && cardTitle && (
										<div className="tumblr-preview__window-title">{ tumblrTitle( cardTitle ) }</div>
									) }
									<div className="tumblr-preview__site-name">{ baseDomain( url ) }</div>
								</div>
							</div>
						)
					) }
				</div>
				<TumblrPostActions />
			</div>
		</div>
	);
};