/**
* WordPress dependencies
*/
import { _x } from '@safe-wordpress/i18n';
/**
* External dependencies
*/
import clsx from 'clsx';
import { castArray, compact, take } from 'lodash';
import md5 from 'md5';
import {
SocialMessageTextPreview,
SocialProfileIcon,
} from '@nelio-content/components';
import { dateI18n } from '@nelio-content/date';
/**
* Internal dependencies
*/
import './style.scss';
import { MaybeSharedLink } from './maybe-shared-link';
import type { PreviewAttributes } from '../../../hooks';
export const LinkedInPreview = ( attrs: PreviewAttributes ): JSX.Element => {
const {
activeProfile: { id: profileId, displayName },
schedule,
textComputed,
type,
} = attrs;
return (
{ displayName }
{ dateI18n(
_x(
'F j, Y',
'text (LinkedIn preview date)',
'nelio-content'
),
schedule
) }
'https://lnkd.in/' + hash( link ) }
/>
{ [ 'image', 'video' ].includes( type ) ? (
) : (
) }
);
};
const MediaPreview = ( attrs: PreviewAttributes ): JSX.Element => {
const { image, video, type } = attrs;
const imageItems = compact( [ ...castArray( image ?? [] ) ] );
const videoItems = compact( [ ...castArray( video ?? [] ) ] );
if ( 'video' === type ) {
return (
);
}
if ( imageItems.length > 1 ) {
const imageSubset = take( imageItems, 4 );
return (
{ imageSubset.map( ( img, i ) => (

{ i === imageSubset.length - 1 &&
imageSubset.length < imageItems.length && (
{ `+${
imageItems.length -
imageSubset.length
}` }
) }
) ) }
);
}
return (
);
};
// =======
// HELPERS
// =======
const hash = ( link: string ): string => {
return md5( link ).substring( 0, 6 );
};