/** * WordPress dependencies */ import { _x } from '@safe-wordpress/i18n'; /** * External dependencies */ import { castArray, compact, isArray } from 'lodash'; import { SocialMessageTextPreview, SocialProfileIcon, } from '@nelio-content/components'; import { dateI18n } from '@nelio-content/date'; import type { Maybe, Url } from '@nelio-content/types'; /** * Internal dependencies */ import './style.scss'; import { MaybeSharedLink } from './maybe-shared-link'; import type { PreviewAttributes } from '../../../hooks'; export const ThreadsPreview = ( attrs: PreviewAttributes ): JSX.Element => { const { activeProfile: { id: profileId, displayName, username }, dateValue, schedule, textComputed, timeValue, type, } = attrs; return (
{ displayName }
@{ username }
{ const result = link.replace( /^(https?:\/\/[^\/]+.{0,15}).*/, '$1' ); if ( result === link ) { return result.replace( /^https?:\/\//, '' ); } return result.replace( /^https?:\/\//, '' ) + '…'; } } /> { [ 'image', 'video', 'multi-media' ].includes( type ) ? ( ) : ( ) }
{ !! dateValue && !! timeValue && dateI18n( _x( 'g:i A · d M Y', 'text (Threads preview date)', 'nelio-content' ), schedule ) } { !! dateValue && ! timeValue && dateI18n( _x( 'd M Y', 'text (Threads preview date)', 'nelio-content' ), schedule ) } { ! dateValue && _x( 'Someday', 'text', 'nelio-content' ) }
); }; const MediaPreview = ( attrs: PreviewAttributes ): JSX.Element => { const { image, video } = attrs; const media = compact( [ ...castArray( image ?? [] ), ...castArray( video ?? [] ), ] ); const isImage = ( u: Maybe< Url > ): boolean => image === u || ( isArray( image ) && image.includes( u ) ); const isVideo = ( u: Maybe< Url > ): boolean => video === u || ( isArray( video ) && video.includes( u ) ); if ( media.length === 1 && isImage( media[ 0 ] ) ) { return ( { ); } if ( media.length === 1 && isVideo( media[ 0 ] ) ) { return (